diff --git a/cmake/compiler-flags-gl.txt b/cmake/compiler-flags-gl.txt index 17882af542..47758bcdbd 100644 --- a/cmake/compiler-flags-gl.txt +++ b/cmake/compiler-flags-gl.txt @@ -148,10 +148,21 @@ src/OpenSHC/UI/MenuItems/BuildingAndStatusMenu/MenuItemRenderFunction_BuildingAn 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/getRubbleGraphicStageForDamageLevel.cpp +src/OpenSHC/Map/TileMapState/returnOwnedMoatAtTile.cpp src/OpenSHC/Map/TileMapState/setSignpostDistanceForCampaignMission.cpp src/OpenSHC/Map/TileMapState/clearDrawBridgeWater.cpp src/OpenSHC/Map/TileMapState/clearFixedSizeTwoBuildingFootprint.cpp +src/OpenSHC/Map/TileMapState/clearRockFootprintFlags.cpp +src/OpenSHC/Map/TileMapState/clearSizeFiveBuildingFootprintAndMoats.cpp +src/OpenSHC/Map/TileMapState/clearTreeFootprintFlags.cpp +src/OpenSHC/Map/TileMapState/floodMoatUnderRemovedBuilding.cpp +src/OpenSHC/Map/TileMapState/isUnitBlockingSizeFiveFootprint.cpp src/OpenSHC/Map/TileMapState/markBuildingFootprintFlag.cpp +src/OpenSHC/Map/TileMapState/placeBarracks.cpp +src/OpenSHC/Map/TileMapState/placeOilsmelter.cpp +src/OpenSHC/Map/TileMapState/renderWallPlacementPreview.cpp +src/OpenSHC/Map/TileMapState/setMiscDisplayLayer.cpp src/OpenSHC/Map/TileMapState/storeMinAndMaxHeightOfArea.cpp src/OpenSHC/Map/TileMapState/unmarkBuildingFootprintFlag.cpp src/OpenSHC/Map/TileMapState/updateGameRelatedValue.cpp @@ -160,9 +171,16 @@ 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/placeKeep.cpp +src/OpenSHC/Map/TileMapState/updatePathLinkagesForBuilding.cpp +src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp src/OpenSHC/Map/TileMapState/setupAllMapSections.cpp src/OpenSHC/Map/TileMapState/setupLogicalMapBorders.cpp src/OpenSHC/Map/TileMapState/updateShowHiLayerOrResetChangedLayer.cpp +src/OpenSHC/Map/TileMapState/validateWallBuildPath.cpp +src/OpenSHC/Map/TileMapState/isTileEnclosedByWalls.cpp +src/OpenSHC/Map/TileMapState/isTileEnclosedByWallsOrGates.cpp +src/OpenSHC/Map/TileMapState/getMaxWallHeightInBrushArea.cpp src/OpenSHC/UI/DisplayElements/RenderTimeUntilDefeatDisplayElement.cpp src/OpenSHC/UI/DisplayElements/GetIfDisplayElementStateNotZero.cpp src/OpenSHC/UI/DisplayElements/FindDisplayElementWithID.cpp @@ -241,6 +259,28 @@ src/OpenSHC/Map/Units/UpdateMiner.cpp src/OpenSHC/Map/Units/UpdateQuarryMason.cpp src/OpenSHC/Map/Units/UpdateDrunkard.cpp src/OpenSHC/Map/Units/UpdateInnkeeper.cpp +src/OpenSHC/Map/TileMapState/placeApplefarm.cpp +src/OpenSHC/Map/TileMapState/placeDairyfarm.cpp +src/OpenSHC/Map/TileMapState/placeDrawbridge.cpp +src/OpenSHC/Map/TileMapState/placeEngineersguild.cpp +src/OpenSHC/Map/TileMapState/placeGatehouseLarge.cpp +src/OpenSHC/Map/TileMapState/placeGatehouseSmall.cpp +src/OpenSHC/Map/TileMapState/placeHopfarm.cpp +src/OpenSHC/Map/TileMapState/placeKillingPit.cpp +src/OpenSHC/Map/TileMapState/placePositiveFearfactor.cpp +src/OpenSHC/Map/TileMapState/placeQuarry.cpp +src/OpenSHC/Map/TileMapState/placeSiegeTent.cpp +src/OpenSHC/Map/TileMapState/placeSiegetowerPlaced.cpp +src/OpenSHC/Map/TileMapState/placeTower.cpp +src/OpenSHC/Map/TileMapState/placeTunnelersguild.cpp +src/OpenSHC/Map/TileMapState/placeWheatfarm.cpp +src/OpenSHC/Map/TileMapState/placeWorkshopOrHovel.cpp +src/OpenSHC/Map/TileMapState/stampBuildingOntoTileMap.cpp +src/OpenSHC/Map/TileMapState/upgradeTowerLogicLayer.cpp +src/OpenSHC/Map/TileMapState/setConstructionGFXLayerBasedOnPlacementChecks.cpp +src/OpenSHC/Map/TileMapState/prepareMap.cpp +src/OpenSHC/Map/TileMapState/toggleFlatView.cpp +src/OpenSHC/Map/TileMapState/checkBuildingCanBePlacedHere.cpp src/OpenSHC/Map/Units/UpdateLion.cpp src/OpenSHC/Map/Units/UpdateMerchant.cpp src/OpenSHC/Map/Units/UpdateKnight.cpp diff --git a/cmake/function-visibility.txt b/cmake/function-visibility.txt index 9349d9bb13..fa81063d80 100644 --- a/cmake/function-visibility.txt +++ b/cmake/function-visibility.txt @@ -121,6 +121,18 @@ OpenSHC::UI::MenuItems::Roundtable::MenuItemActionHandler_Roundtable_Main OpenSHC::Synchrony::GameSynchronyState::isAIPlayer OpenSHC::Map::TileMapState::updateMoatCountdownTimers OpenSHC::Map::TileMapState::recountTotalOwnedMoats +OpenSHC::Map::TileMapState::createPlateau + OpenSHC::Map::TileMapState::getTileForBrush +OpenSHC::Map::TileMapState::isValidCastleSiteLocation + OpenSHC::Map::TileMapState::getTileForBrush +OpenSHC::Map::TileMapState::setLand + OpenSHC::Map::TileMapState::getTileForBrush +OpenSHC::Map::TileMapState::useEraserBrush + OpenSHC::Map::TileMapState::getTileForBrush +OpenSHC::Map::TileMapState::useLevelBrush + OpenSHC::Map::TileMapState::getTileForBrush +OpenSHC::Map::TileMapState::useTerrainHeightBrush + OpenSHC::Map::TileMapState::getTileForBrush OpenSHC::UI::HoveredState::Constructor_HoveredState OpenSHC::UI::HoveredState::clearHoveredState OpenSHC::Map::Units::UpdateBurningMan diff --git a/src/OpenSHC/AI/AICState/updateAIPlayerState.cpp b/src/OpenSHC/AI/AICState/updateAIPlayerState.cpp index e33c3afe95..ac96b6a6dc 100644 --- a/src/OpenSHC/AI/AICState/updateAIPlayerState.cpp +++ b/src/OpenSHC/AI/AICState/updateAIPlayerState.cpp @@ -48,7 +48,7 @@ namespace AI { MACRO_CALL_MEMBER(OpenSHC::AI::AICState_Func::setCurrentAttackRaidParameter, this)(playerID); // read into a local first: without it the scratch registers of this increment come out swapped int attackedPlayerID = DAT_GameState::instance.playerDataArray[playerID].attackedPlayerID; - ++DAT_GameState::instance.playerDataArray[attackedPlayerID].attackedByPlayerArrayUnk[playerID][0]; + ++DAT_GameState::instance.playerDataArray[attackedPlayerID].attackedByPlayer[playerID].attacks; } else { // send own units back to keep or campfire MACRO_CALL_MEMBER(OpenSHC::AI::AICState_Func::aiRetreatUnits, this)(playerID); diff --git a/src/OpenSHC/Game/GameStateStructures/processUnitLossStatistic.cpp b/src/OpenSHC/Game/GameStateStructures/processUnitLossStatistic.cpp index c1688403b1..691aec7bf5 100644 --- a/src/OpenSHC/Game/GameStateStructures/processUnitLossStatistic.cpp +++ b/src/OpenSHC/Game/GameStateStructures/processUnitLossStatistic.cpp @@ -78,8 +78,8 @@ namespace Game { DAT_GameSynchronyState::instance.finalResults.finalTroopsKilledWeighted[enemyPlayerID] += lossValue; } } - DAT_GameState::instance.playerDataArray[playerID].attackedByPlayerArrayUnk[enemyPlayerID][2] - = DAT_GameState::instance.playerDataArray[playerID].attackedByPlayerArrayUnk[enemyPlayerID][2] + 1; + DAT_GameState::instance.playerDataArray[playerID].attackedByPlayer[enemyPlayerID].unitsLost + = DAT_GameState::instance.playerDataArray[playerID].attackedByPlayer[enemyPlayerID].unitsLost + 1; } if (DAT_UnitsState::instance.units[unitID].isSelected != 0) { DAT_GameCore::instance.countdown = 1; diff --git a/src/OpenSHC/Game/GameStateStructures/setLastEncounteredTroopUnit.cpp b/src/OpenSHC/Game/GameStateStructures/setLastEncounteredTroopUnit.cpp index ef2e2fb7cb..c05ad31b4a 100644 --- a/src/OpenSHC/Game/GameStateStructures/setLastEncounteredTroopUnit.cpp +++ b/src/OpenSHC/Game/GameStateStructures/setLastEncounteredTroopUnit.cpp @@ -36,9 +36,11 @@ namespace Game { = DAT_UnitsState::instance.units[enemyUnitID].uid; } DAT_GameState::instance.playerDataArray[playerID] - .attackedByPlayerArrayUnk[DAT_UnitsState::instance.units[unitID].lastEncounteredEnemyPlayerID][3] + .attackedByPlayer[DAT_UnitsState::instance.units[unitID].lastEncounteredEnemyPlayerID] + .troopEncounters = DAT_GameState::instance.playerDataArray[playerID] - .attackedByPlayerArrayUnk[DAT_UnitsState::instance.units[unitID].lastEncounteredEnemyPlayerID][3] + .attackedByPlayer[DAT_UnitsState::instance.units[unitID].lastEncounteredEnemyPlayerID] + .troopEncounters + 1; } diff --git a/src/OpenSHC/Game/Player/AttackedByPlayerStatistics.hpp b/src/OpenSHC/Game/Player/AttackedByPlayerStatistics.hpp new file mode 100644 index 0000000000..b859d02bfb --- /dev/null +++ b/src/OpenSHC/Game/Player/AttackedByPlayerStatistics.hpp @@ -0,0 +1,34 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/Game/Player/AttackedByPlayerStatistics.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace Game { + namespace Player { + +#pragma pack(push, 1) + // SIZE: 0x00000020 + typedef struct AttackedByPlayerStatistics { + + int attacks; // 0x00000000 length: 4 + int buildingsDestroyed; // 0x00000004 length: 4 + int unitsLost; // 0x00000008 length: 4 + int troopEncounters; // 0x0000000C length: 4 + int field_0x10; // 0x00000010 length: 4 + int field_0x14; // 0x00000014 length: 4 + int field_0x18; // 0x00000018 length: 4 + int field_0x1c; // 0x0000001C length: 4 + + } AttackedByPlayerStatistics; +#pragma pack(pop) + + static_assert_cpp98_obj(sizeof(AttackedByPlayerStatistics) == 32, AttackedByPlayerStatistics); + } // namespace Player +} // namespace Game +} // namespace OpenSHC diff --git a/src/OpenSHC/Game/Player/PlayerData.hpp b/src/OpenSHC/Game/Player/PlayerData.hpp index c9c2f94d92..124919c7bd 100644 --- a/src/OpenSHC/Game/Player/PlayerData.hpp +++ b/src/OpenSHC/Game/Player/PlayerData.hpp @@ -13,6 +13,7 @@ #include "OpenSHC/AI/AIStrengthTypeInt.hpp" #include "OpenSHC/AI/AITypeInt.hpp" #include "OpenSHC/Coordinates/XYPairShort.hpp" +#include "OpenSHC/Game/Player/AttackedByPlayerStatistics.hpp" #include "OpenSHC/Game/Player/BuildingEntryInfo.hpp" #include "OpenSHC/Game/Player/Enums/StorageMarketFailStateEnumInt.hpp" #include "OpenSHC/Game/Player/UnknownPlayerDataStructure.hpp" @@ -29,6 +30,7 @@ namespace Game { using OpenSHC::AI::AIStrengthTypeInt; using OpenSHC::AI::AITypeInt; using OpenSHC::Coordinates::XYPairShort; + using OpenSHC::Game::Player::AttackedByPlayerStatistics; using OpenSHC::Game::Player::BuildingEntryInfo; using OpenSHC::Game::Player::UnknownPlayerDataStructure; using OpenSHC::Game::Player::Enums::StorageMarketFailStateEnumInt; @@ -329,7 +331,7 @@ namespace Game { int totalMaxDefaultTroops; // 0x00002BD0 length: 4 int attackedPlayerID_2Unk; // 0x00002BD4 length: 4 int attackedPlayerID; // 0x00002BD8 length: 4 - int attackedByPlayerArrayUnk[10][8]; // 0x00002BDC length: 320 + AttackedByPlayerStatistics attackedByPlayer[10]; // 0x00002BDC length: 320 int aivUnitLocationSlots[22][10]; // 0x00002D1C length: 880 int aivUnitLocationSlotLocationCount[22]; // 0x0000308C length: 88 int totalTroopsType0; // 0x000030E4 length: 4 diff --git a/src/OpenSHC/Map/Buildings/BuildingLogicalState.hpp b/src/OpenSHC/Map/Buildings/BuildingLogicalState.hpp index cfb98da970..e7865af778 100644 --- a/src/OpenSHC/Map/Buildings/BuildingLogicalState.hpp +++ b/src/OpenSHC/Map/Buildings/BuildingLogicalState.hpp @@ -13,6 +13,7 @@ namespace Map { namespace Buildings { typedef enum BuildingLogicalState { + BLS_NONE = 0, // 0x00000000 BLS_INITIAL = 1, // 0x00000001 BLS_NORMAL = 2, // 0x00000002 BLS_REMOVE = 3 // 0x00000003 diff --git a/src/OpenSHC/Map/TerrainDefinedData.hpp b/src/OpenSHC/Map/TerrainDefinedData.hpp index ad54d58f0d..ca7cacc2a7 100644 --- a/src/OpenSHC/Map/TerrainDefinedData.hpp +++ b/src/OpenSHC/Map/TerrainDefinedData.hpp @@ -46,7 +46,7 @@ namespace Map { XYPair Stockpile_BuildingPartsOffsets[4]; // 0x000001BC length: 32 XYPair StockpilePathableOffsets[9]; // 0x000001DC length: 72 undefined1 padding_0x224[64]; // 0x00000224 length: 64 - XYPair field_0x264[3][12]; // 0x00000264 length: 288 + XYPair keepDoorOffsets[3][4][3]; // 0x00000264 length: 288 Point8IntXY keepOutbuildingOffsets_0x384[3][4]; // 0x00000384 length: 96 Point8IntXY keepOutbuildingOffsets_0x3e4[3][4]; // 0x000003E4 length: 96 XYPair field_0x444[24]; // 0x00000444 length: 192 diff --git a/src/OpenSHC/Map/TileMapState.func.hpp b/src/OpenSHC/Map/TileMapState.func.hpp index a8a7996bd7..4a91acc93d 100644 --- a/src/OpenSHC/Map/TileMapState.func.hpp +++ b/src/OpenSHC/Map/TileMapState.func.hpp @@ -492,7 +492,7 @@ namespace Map { void (TileMapState::*)(), false, Address::SHC_3BB0A8C1_0x005017A0, &TileMapState::forceFullTileMapRedraw) forceFullTileMapRedraw; - MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(uint, int, int), false, Address::SHC_3BB0A8C1_0x005017C0, + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, int, int), false, Address::SHC_3BB0A8C1_0x005017C0, &TileMapState::useEraserBrush) useEraserBrush; @@ -660,7 +660,7 @@ namespace Map { &TileMapState::applyTreeBrushToLogicalLayer) applyTreeBrushToLogicalLayer; - MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(uint, int, uint), false, Address::SHC_3BB0A8C1_0x00508EC0, + MACRO_FUNCTION_RESOLVER(void (TileMapState::*)(int, int, uint), false, Address::SHC_3BB0A8C1_0x00508EC0, &TileMapState::eraseAreaWithBrush) eraseAreaWithBrush; @@ -688,7 +688,7 @@ namespace Map { void (TileMapState::*)(), false, Address::SHC_3BB0A8C1_0x005114C0, &TileMapState::updatePitchDitches) updatePitchDitches; - MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(int, uint, uint), false, Address::SHC_3BB0A8C1_0x005116E0, + MACRO_FUNCTION_RESOLVER(int (TileMapState::*)(int, int, int), false, Address::SHC_3BB0A8C1_0x005116E0, &TileMapState::placePitchDitch) placePitchDitch; diff --git a/src/OpenSHC/Map/TileMapState.hpp b/src/OpenSHC/Map/TileMapState.hpp index a1c432c5e5..9c9145a33b 100644 --- a/src/OpenSHC/Map/TileMapState.hpp +++ b/src/OpenSHC/Map/TileMapState.hpp @@ -500,7 +500,7 @@ namespace Map { void forceFullTileMapRedraw(); - void useEraserBrush(uint x, int y, int brush); + void useEraserBrush(int x, int y, int brush); void updateShowHiLayerOrResetChangedLayer(); @@ -599,7 +599,7 @@ namespace Map { void applyTreeBrushToLogicalLayer(int treeID, BOOLEnum noVariation); - void eraseAreaWithBrush(uint x, int y, uint brush); + void eraseAreaWithBrush(int x, int y, uint brush); void updateGfxLayer(); @@ -613,7 +613,7 @@ namespace Map { void updatePitchDitches(); - int placePitchDitch(int playerID, uint x, uint y); + int placePitchDitch(int playerID, int x, int y); void updateGameRelatedValue(); diff --git a/src/OpenSHC/Map/TileMapState/applyTreeBrushToLogicalLayer.cpp b/src/OpenSHC/Map/TileMapState/applyTreeBrushToLogicalLayer.cpp new file mode 100644 index 0000000000..a638caada9 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/applyTreeBrushToLogicalLayer.cpp @@ -0,0 +1,53 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_TREE_VARIATION; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508DD0 + void TileMapState::applyTreeBrushToLogicalLayer(int treeID, BOOLEnum noVariation) + { + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[MACRO_CALL_MEMBER( + OpenSHC::Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, DAT_LandscapeState::ptr)( + DAT_LandscapeState::instance.trees[treeID].treeType, DAT_LandscapeState::instance.trees[treeID].stage)]; + int tile = DAT_LandscapeState::instance.trees[treeID].xPosition + + DAT_ViewportRenderState::instance.translationMatrix[DAT_LandscapeState::instance.trees[treeID].yPosition] + .addXgetTile; + int brushY = DAT_LandscapeState::instance.trees[treeID].yPosition; + int const baseTile = tile; + int const baseY = brushY; + for (int tileIndex = 0; tileIndex < brushSize; tileIndex++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, tileIndex, &tile, &brushY, baseTile, baseY); + if ((this->LogicLayer[tile] & L_BORDER) != 0) { + break; + } + if ((this->LogicLayer[tile] & (L_SEA | L_MARSH | L_MOAT)) != 0) { + continue; + } + if (noVariation) { + this->LogicLayer[tile] &= ~L_TREE_VARIATION; + } else { + this->LogicLayer[tile] |= L_TREE_VARIATION; + } + } + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, DAT_PathFindingState::ptr)(7, + DAT_LandscapeState::instance.trees[treeID].xPosition, DAT_LandscapeState::instance.trees[treeID].yPosition); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/checkBuildingCanBePlacedHere.cpp b/src/OpenSHC/Map/TileMapState/checkBuildingCanBePlacedHere.cpp new file mode 100644 index 0000000000..2abc91b5eb --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/checkBuildingCanBePlacedHere.cpp @@ -0,0 +1,782 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingFailReasonEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingPlacementFailState.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingPlacementWarning.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::BuildingFailReasonEnum; + using OpenSHC::Map::Buildings::Enums::BPFS_BLOCKED; + using OpenSHC::Map::Buildings::Enums::BPFS_NONE; + using OpenSHC::Map::Buildings::Enums::BPFS_OFF_MAP; + using OpenSHC::Map::Buildings::Enums::BPW_NONE; + using OpenSHC::Map::Enums::CD_UNSPECIFIED; + using OpenSHC::Map::LogicHelpers::L2_OASIS_GRASS; + using OpenSHC::Map::LogicHelpers::L2_SCRUB; + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BOULDERS; + using OpenSHC::Map::LogicHelpers::L_IRON; + using OpenSHC::Map::LogicHelpers::L_OIL; + using OpenSHC::Map::LogicHelpers::L_RIVER; + + // FUNCTION: STRONGHOLDCRUSADER 0x005037B0 + void TileMapState::checkBuildingCanBePlacedHere( + int playerID, uint x, uint y, MappersEnumShort commandBuildingType, int buildingSize) + { + int tileIndex; + uint const startX = x; + uint const startY = y; + int keepRangeBonus = 0; + BOOLEnum sizeDefaulted = FALSE; + if (buildingSize < 0) { + buildingSize = 2; + sizeDefaulted = TRUE; + } + this->buildingPlacementFail = BPFS_NONE; + this->placementWarning = BPW_NONE; + this->field_0x554944 = 0; + this->uiBuildingRotation = CD_UNSPECIFIED; + MappersEnum const command = (MappersEnum)commandBuildingType; + this->buildingSpriteSheetID_1 + = DAT_BuildingDefinedData::instance + .Building_SpriteSheet_ID_Array_1[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)] + .intValue; + this->buildingSpriteID1 = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getSpriteID, DAT_BuildingsState::ptr)(command); + this->buildingSpriteID2 = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getSpriteID2, DAT_BuildingsState::ptr)(command); + this->buildingHeightLimit = DAT_BuildingDefinedData::instance.BuildingPlacement_HeightLimit[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)]; + this->buildingMaxHeightDifference + = DAT_BuildingDefinedData::instance.BuildingPlacement_MaxHeightDifference[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)]; + this->buildingPlacementProperty_3 + = DAT_BuildingDefinedData::instance.BuildingPlacement_Property_3[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)]; + this->buildingPlacementProperty_4 + = DAT_BuildingDefinedData::instance.BuildingPlacement_Property_4[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)]; + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY + || DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] != -1 + || DAT_GameSynchronyState::instance.currentAIArray[playerID] == 0) { + this->buildingPlacementProperty_4 = 0; + } + this->buildingPlacementProperty_5 + = DAT_BuildingDefinedData::instance.BuildingPlacement_Property_5[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)]; + this->buildingPlacementProperty_6 + = DAT_BuildingDefinedData::instance.BuildingPlacement_Property_6[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)]; + this->buildingPlacementProperty_7 + = DAT_BuildingDefinedData::instance.BuildingPlacement_Property_7[MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command)]; + if (commandBuildingType == OpenSHC::Commands::M_MAPPER_SIEGE_TOWER_BASE) { + return; + } + int boulderCount = 0; + int ironCount = 0; + int oilCount = 0; + int fertileCount = 0; + int grassCount = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::storeMinAndMaxHeightOfArea, this)(x, y, buildingSize); + if (!sizeDefaulted) { + BOOLEnum checkSuitability = TRUE; + switch (commandBuildingType) { + case OpenSHC::Commands::M_MAPPER_WOODSMAN: + case OpenSHC::Commands::M_MAPPER_OXENBASE: + case OpenSHC::Commands::M_MAPPER_QUARRY: + case OpenSHC::Commands::M_MAPPER_TUNNEL: + case OpenSHC::Commands::M_MAPPER_TUNNEL_CONSTRUCTION: + case OpenSHC::Commands::M_MAPPER_WHEATFARM: + case OpenSHC::Commands::M_MAPPER_HOPSFARM: + case OpenSHC::Commands::M_MAPPER_APPLEFARM: + case OpenSHC::Commands::M_MAPPER_CATTLEFARM: + case OpenSHC::Commands::M_MAPPER_IRON_MINE: + case OpenSHC::Commands::M_MAPPER_PITCH_WORKINGS: + case OpenSHC::Commands::M_MAPPER_QUARRYPILE: + case OpenSHC::Commands::M_MAPPER_POND1: + case OpenSHC::Commands::M_MAPPER_POND2_SMALL: + case OpenSHC::Commands::M_MAPPER_POND3_LARGE1: + case OpenSHC::Commands::M_MAPPER_POND4_LARGE2: + checkSuitability = FALSE; + break; + case OpenSHC::Commands::M_MAPPER_STORES: + case OpenSHC::Commands::M_MAPPER_GRANARY: + case OpenSHC::Commands::M_MAPPER_ARMOURY: + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + tileIndex, buildingSize); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)(playerID, this->buildingX + x, this->buildingY + y, 3)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + this->buildingPlacementFail = BPFS_BLOCKED; + break; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + } + break; + case OpenSHC::Commands::M_MAPPER_DOG_CAGE: + if (DAT_GameState::instance.playerDataArray[playerID].dogCageCount >= 10) { + this->buildingPlacementFail = BPFS_BLOCKED; + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_1000; + return; + } + case OpenSHC::Commands::M_MAPPER_KILLING_PIT: + case OpenSHC::Commands::M_MAPPER_PITCH_DITCH: + case OpenSHC::Commands::M_MAPPER_DRAWBRIDGE: + keepRangeBonus = 5; + case OpenSHC::Commands::M_MAPPER_GATEHOUSE: + case OpenSHC::Commands::M_MAPPER_GATE_MAIN: + case OpenSHC::Commands::M_MAPPER_GATE_INNER: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD: + case OpenSHC::Commands::M_MAPPER_GATE_POSTERN: + case OpenSHC::Commands::M_MAPPER_MOAT: + case OpenSHC::Commands::M_MAPPER_ANTIMOAT: + case OpenSHC::Commands::M_MAPPER_TOWER1: + case OpenSHC::Commands::M_MAPPER_TOWER2: + case OpenSHC::Commands::M_MAPPER_TOWER3: + case OpenSHC::Commands::M_MAPPER_TOWER4: + case OpenSHC::Commands::M_MAPPER_TOWER5: + 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_GATE_STONE1A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE1B: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2B: + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR) { + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) { + break; + } + int distance; + int range; + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + if (MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::isAIPlayer, + DAT_GameSynchronyState::ptr)(playerID)) { + distance = 15; + range = 7; + } else { + distance = 15; + range = 7; + } + } else { + distance = 30; + range = 30; + } + BOOLEnum siteClear; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + tileIndex, buildingSize); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)( + playerID, this->buildingX + x, this->buildingY + y, distance)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + siteClear = FALSE; + break; + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::isOpponentBuildingInRange, + DAT_PathFindingState::ptr)( + playerID, this->buildingX + x, this->buildingY + y, range, -1, -1, -1)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + siteClear = FALSE; + break; + } + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::isTileInRangeOfKeepRange, + DAT_PathFindingState::ptr)(playerID, this->buildingX + x, this->buildingY + y, + MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::getCastleBuildRangeForMapSize, this)() + + keepRangeBonus)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_18; + siteClear = FALSE; + break; + } + siteClear = TRUE; + } else { + siteClear = TRUE; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isSignPostWithinDistance, + DAT_PathFindingState::ptr)( + x, y, DAT_GameState::instance.mapAndTime.unk_signpostDistance + 5)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_21; + } else if (siteClear) { + break; + } + this->buildingPlacementFail = BPFS_BLOCKED; + if (this->buildingPlacementFailReason + == OpenSHC::Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_18; + } + } else { + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + tileIndex, buildingSize); + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::isOpponentBuildingInRange, + DAT_PathFindingState::ptr)( + playerID, this->buildingX + x, this->buildingY + y, 7, -1, -1, -1)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + this->buildingPlacementFail = BPFS_BLOCKED; + break; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + } + break; + 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_ARAB_BALLISTA: + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT) { + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + tileIndex, buildingSize); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)(playerID, this->buildingX + x, this->buildingY + y, 3)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + this->buildingPlacementFail = BPFS_BLOCKED; + break; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + } + break; + default: + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT) { + int const distance + = DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY ? 15 : 30; + BOOLEnum noEnemyNearby = TRUE; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + tileIndex, buildingSize); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)( + playerID, this->buildingX + x, this->buildingY + y, distance)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + noEnemyNearby = FALSE; + break; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isSignPostWithinDistance, + DAT_PathFindingState::ptr)( + x, y, DAT_GameState::instance.mapAndTime.unk_signpostDistance + 5)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_21; + this->buildingPlacementFail = BPFS_BLOCKED; + } else if (!noEnemyNearby) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + } + break; + } + if (checkSuitability && this->buildingPlacementFail == BPFS_NONE) { + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + tileIndex, buildingSize); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::findSomeSuitableLocationUnk, + DAT_PathFindingState::ptr)(playerID, this->buildingX + x, this->buildingY + y, 2)) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + this->buildingPlacementFail = BPFS_BLOCKED; + break; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + } + } + if (commandBuildingType == OpenSHC::Commands::M_MAPPER_DRAWBRIDGE && this->buildingMaxHeight > 12) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + tileIndex, buildingSize); + uint const tileX = this->buildingX + x; + uint const tileY = this->buildingY + y; + if (tileX > MC_MAP_XY_LIMIT_INCLUSIVE) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (tileY > MC_MAP_XY_LIMIT_INCLUSIVE) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + tileX] == 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + this->buildingX + x; + uint const logic = this->LogicLayer[tile]; + if ((logic & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if ((logic & L_BOULDERS) != 0) { + boulderCount++; + } + if ((logic & L_IRON) != 0) { + ironCount++; + } + if ((logic & L_OIL) != 0) { + oilCount++; + } + if ((logic & L_RIVER) == 0) { + char const logic2 = this->Logic2Layer[tile]; + if ((logic2 & L2_OASIS_GRASS) != 0) { + fertileCount++; + grassCount++; + } + if ((logic2 & L2_THICK_SCRUB) != 0) { + fertileCount++; + grassCount++; + } + if ((logic2 & L2_SCRUB) != 0) { + fertileCount++; + } + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + short const commandShort = commandBuildingType; + if (commandShort == OpenSHC::Commands::M_MAPPER_CATTLEFARM + || commandShort == OpenSHC::Commands::M_MAPPER_WHEATFARM + || commandShort == OpenSHC::Commands::M_MAPPER_HOPSFARM + || commandShort == OpenSHC::Commands::M_MAPPER_APPLEFARM) { + if (fertileCount < this->constructionTileCount) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_22; + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + if (grassCount < 50) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_23; + this->buildingPlacementFail = BPFS_BLOCKED; + } + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_QUARRY) { + if (boulderCount < 8) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_KEEP1 || commandShort == OpenSHC::Commands::M_MAPPER_KEEP2 + || commandShort == OpenSHC::Commands::M_MAPPER_KEEP3) { + int const keepIndex = command - OpenSHC::Commands::M_MAPPER_KEEP1; + for (int part = 0; part < countof(DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0]); part++) { + if (!MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, DAT_ViewportRenderState::ptr)( + DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][part].x + x, + DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][part].y + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][part].y + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][part].x + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + } + x += DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[keepIndex][0].xOffset; + y += DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[keepIndex][0].yOffset; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 7); + uint const tileY = this->buildingY + y; + uint const tileX = this->buildingX + x; + if (tileX > MC_MAP_XY_LIMIT_INCLUSIVE || tileY > MC_MAP_XY_LIMIT_INCLUSIVE + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + tileX] + == 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + x = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[keepIndex][0].xOffset + startX; + y = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[keepIndex][0].yOffset + startY; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 5); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(x + this->buildingX, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_GATE_WOOD1A + || commandShort == OpenSHC::Commands::M_MAPPER_GATE_WOOD1B + || commandShort == OpenSHC::Commands::M_MAPPER_GATE_WOOD1C + || commandShort == OpenSHC::Commands::M_MAPPER_GATE_WOOD1D) { + int const gateIndex = command - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A; + x += DAT_TerrainDefinedData::instance.gateTowerChecks[gateIndex].x1; + y += DAT_TerrainDefinedData::instance.gateTowerChecks[gateIndex].y1; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 3); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(this->buildingX + x, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + x = DAT_TerrainDefinedData::instance.gateTowerChecks[gateIndex].x2 + startX; + y = DAT_TerrainDefinedData::instance.gateTowerChecks[gateIndex].y2 + startY; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 3); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(x + this->buildingX, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + for (int part = 0; part < countof(DAT_TerrainDefinedData::instance.gateHouseTiles[0]); part++) { + if (!MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, DAT_ViewportRenderState::ptr)(startX + + DAT_TerrainDefinedData::instance + .gateHouseTiles[command - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A][part] + .x, + DAT_TerrainDefinedData::instance + .gateHouseTiles[command - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A][part] + .y + + startY)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .gateHouseTiles[command + - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A][part] + .y + + startY] + .addXgetTile + + DAT_TerrainDefinedData::instance + .gateHouseTiles[command - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A][part] + .x + + startX; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + } + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_IRON_MINE) { + if (ironCount < 4) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_NOT_IRON_ORE; + this->buildingPlacementFail = BPFS_BLOCKED; + } + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_PITCH_WORKINGS) { + if (oilCount < 1) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_NOT_OIL_MARSH; + this->buildingPlacementFail = BPFS_BLOCKED; + } + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_STORES) { + if (DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id + == 0) { + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getEmptyBuildingCount, + DAT_BuildingsState::ptr)(playerID, OpenSHC::Map::Buildings::BT_STOCKPILE) + >= 32) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::hasBuildingAsNeighbour, + DAT_BuildingsState::ptr)(playerID, x, y, buildingSize, OpenSHC::Map::Buildings::BT_STOCKPILE)) { + return; + } + this->buildingPlacementFail = BPFS_BLOCKED; + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_NOT_ADJ_STOCKPILE; + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_GRANARY) { + if (DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_GRANARY] + .id + == 0) { + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getEmptyBuildingCount, + DAT_BuildingsState::ptr)(playerID, OpenSHC::Map::Buildings::BT_GRANARY) + >= 8) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::hasBuildingAsNeighbour, + DAT_BuildingsState::ptr)(playerID, x, y, buildingSize, OpenSHC::Map::Buildings::BT_GRANARY)) { + return; + } + this->buildingPlacementFail = BPFS_BLOCKED; + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_NOT_ADJ_GRANARY; + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_ARMOURY) { + if (DAT_GameState::instance.playerDataArray[playerID] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_ARMORY] + .id + == 0) { + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getEmptyBuildingCount, + DAT_BuildingsState::ptr)(playerID, OpenSHC::Map::Buildings::BT_ARMORY) + >= 8) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::hasBuildingAsNeighbour, + DAT_BuildingsState::ptr)(playerID, x, y, buildingSize, OpenSHC::Map::Buildings::BT_ARMORY)) { + return; + } + this->buildingPlacementFail = BPFS_BLOCKED; + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_NOT_ADJ_ARMORY; + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_BARRACKS_EURO + || commandShort == OpenSHC::Commands::M_MAPPER_BARRACKS_ARAB) { + x += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][0].x; + y += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][0].y; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 5); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(this->buildingX + x, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + x = startX + DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][1].x; + y = startY + DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][1].y; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 5); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(this->buildingX + x, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + x = startX + DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][2].x; + y = startY + DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][2].y; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 5); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(this->buildingX + x, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_ENGINEERS_GUILD + || commandShort == OpenSHC::Commands::M_MAPPER_TUNNELERS_GUILD) { + x += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][1].x; + y += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[this->DAT_TempBuildingRotation][1].y; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 5); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(this->buildingX + x, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, command, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_OIL_SMELTER) { + x += DAT_TerrainDefinedData::instance.field_0x19c[this->DAT_TempBuildingRotation].x; + y += DAT_TerrainDefinedData::instance.field_0x19c[this->DAT_TempBuildingRotation].y; + tileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 4); + if (!MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + DAT_ViewportRenderState::ptr)(this->buildingX + x, this->buildingY + y)) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->buildingPlacementFail = BPFS_OFF_MAP; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, OpenSHC::Commands::M_MAPPER_OIL_SMELTER, FALSE)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + return; + } + if (commandShort == OpenSHC::Commands::M_MAPPER_TUNNEL_CONSTRUCTION) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::algTunnelerFindTarget, + DAT_PathFindingState::ptr)(playerID, 0, 76, x, y); + if (DAT_PathFindingState::instance.ALG_TargetTile == 0) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/checkDrawbridgePlacement.cpp b/src/OpenSHC/Map/TileMapState/checkDrawbridgePlacement.cpp new file mode 100644 index 0000000000..af6001b0e7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/checkDrawbridgePlacement.cpp @@ -0,0 +1,99 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingPlacementFailState.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::Enums::BPFS_BLOCKED; + using OpenSHC::Map::Buildings::Enums::BPFS_NONE; + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + + using OpenSHC::Map::Buildings::BuildingLogicalState; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FA2D0 + void TileMapState::checkDrawbridgePlacement(int x, int y) + { + if (this->buildingPlacementFail != BPFS_NONE) { + return; + } + this->buildingPlacementFail = BPFS_BLOCKED; + + for (int rotation = 0; rotation < countof(DAT_TerrainDefinedData::instance.drawBridgeOffsets); rotation++) { + int buildings[countof(DAT_TerrainDefinedData::instance.drawBridgeOffsets[0])]; + for (int count = 0; count < countof(buildings); count++) { + buildings[count] = 0; + int const offsetY = DAT_TerrainDefinedData::instance.drawBridgeOffsets[rotation][count].y + y; + int const offsetX = DAT_TerrainDefinedData::instance.drawBridgeOffsets[rotation][count].x + x; + if (offsetX < 0 || offsetX > MC_MAP_XY_LIMIT_INCLUSIVE || offsetY < 0 + || offsetY > MC_MAP_XY_LIMIT_INCLUSIVE + || !DAT_ViewportRenderState::instance + .DAT_BinaryTileMap400x400[offsetY * MC_MAP_XY_LIMIT + offsetX]) { + break; + } + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.drawBridgeOffsets[rotation][count].y + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.drawBridgeOffsets[rotation][count].x + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + break; + } + buildings[count] = this->BuildingLayer[tile]; + } + + if (buildings[0] == 0) { + continue; + } + if (DAT_BuildingsState::instance.buildings[buildings[0]].logicalState + != OpenSHC::Map::Buildings::BLS_NORMAL) { + continue; + } + int span; + if (DAT_BuildingsState::instance.buildings[buildings[0]].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE) { + span = 7; + } else if (DAT_BuildingsState::instance.buildings[buildings[0]].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSESMALL) { + span = 5; + } else { + continue; + } + if (DAT_BuildingsState::instance.buildings[buildings[0]].buildingVariation == 81) { + if (rotation == 1 || rotation == 3) { + continue; + } + } else if (DAT_BuildingsState::instance.buildings[buildings[0]].buildingVariation == 80) { + if (rotation == 0 || rotation == 2) { + continue; + } + } + + int i = 0; + int matching = 0; + for (; i < span; i++) { + if (buildings[i] == buildings[0]) { + matching++; + } + } + if (matching != span) { + continue; + } + this->uiBuildingRotation = rotation * 2; + this->field_0x554944 = this->uiBuildingRotation * 25; + this->buildingPlacementFail = BPFS_NONE; + return; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearRockFootprintFlags.cpp b/src/OpenSHC/Map/TileMapState/clearRockFootprintFlags.cpp new file mode 100644 index 0000000000..6873ecda59 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearRockFootprintFlags.cpp @@ -0,0 +1,29 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_ROCKY; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB970 + void TileMapState::clearRockFootprintFlags(int rockID) + { + int const rockX = DAT_LandscapeState::instance.rocks[rockID].x; + int const rockY = DAT_LandscapeState::instance.rocks[rockID].y; + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, DAT_LandscapeState::instance.rocks[rockID].size); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + rockY].addXgetTile + + this->buildingX + rockX; + buildingSizeTileIndex++; + this->LogicLayer[tile] &= ~L_ROCKY; + this->OrganismLayer[tile] = 0; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearSizeFiveBuildingFootprintAndMoats.cpp b/src/OpenSHC/Map/TileMapState/clearSizeFiveBuildingFootprintAndMoats.cpp new file mode 100644 index 0000000000..50e66d3388 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearSizeFiveBuildingFootprintAndMoats.cpp @@ -0,0 +1,53 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L2_EARTH_AND_STONES; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_MOAT; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508760 + void TileMapState::clearSizeFiveBuildingFootprintAndMoats(int x, int y) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, 5); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + int const buildingID = this->BuildingLayer[tile]; + int const variation = DAT_BuildingsState::instance.buildings[buildingID].buildingVariation; + this->LogicLayer[tile] &= ~L_BUILDING; + if (DAT_TerrainDefinedData::instance.DrawbridgeOrientationMapping[variation / 2][buildingSizeTileIndex] + != 0) { + uint const moatID + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)(tile); + if (moatID != 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].noRubble == 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatData, this)(moatID); + this->LogicLayer[tile] &= ~L_MOAT; + this->Logic2Layer[tile] |= L2_EARTH_AND_STONES; + this->BuildingWasLayer[tile] = 0; + this->HeightLayer[tile] = 8; + } else { + this->LogicLayer[tile] |= L_MOAT; + } + } + } + if ((this->LogicLayer[tile] & L_MOAT) == 0) { + this->Logic2Layer[tile] |= L2_EARTH_AND_STONES; + this->BuildingWasLayer[tile] = 0; + } + this->BuildingLayer[tile] = 0; + buildingSizeTileIndex++; + this->ChangedLayer[tile] = 2; + } while (buildingSizeTileIndex < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/clearTreeFootprintFlags.cpp b/src/OpenSHC/Map/TileMapState/clearTreeFootprintFlags.cpp new file mode 100644 index 0000000000..797b42118a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/clearTreeFootprintFlags.cpp @@ -0,0 +1,31 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_TREE; + using OpenSHC::Map::LogicHelpers::L_TREE_VARIATION; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB8E0 + void TileMapState::clearTreeFootprintFlags(int treeID) + { + int const treeX = DAT_LandscapeState::instance.trees[treeID].xPosition; + int const treeY = DAT_LandscapeState::instance.trees[treeID].yPosition; + this->OrganismLayer[DAT_LandscapeState::instance.trees[treeID].tile] = 0; + this->LogicLayer[DAT_LandscapeState::instance.trees[treeID].tile] &= ~L_TREE; + int index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, DAT_LandscapeState::instance.trees[treeID].size); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + treeY].addXgetTile + + treeX + this->buildingX; + index++; + this->LogicLayer[tile] &= ~L_TREE_VARIATION; + } while (index < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/computeTileCliffEdgeFlags.cpp b/src/OpenSHC/Map/TileMapState/computeTileCliffEdgeFlags.cpp new file mode 100644 index 0000000000..1a45f9c14d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/computeTileCliffEdgeFlags.cpp @@ -0,0 +1,113 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/LogicHelpers/RiverFall.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::CD_EAST; + using OpenSHC::Map::Enums::CD_NORTH; + using OpenSHC::Map::Enums::CD_SOUTH; + using OpenSHC::Map::Enums::CD_UPPER_LIMIT; + using OpenSHC::Map::Enums::CD_WEST; + using OpenSHC::Map::LogicHelpers::L2_BEACH; + 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::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::RF_EAST_SIDE; + using OpenSHC::Map::LogicHelpers::RF_SOUTH_AND_EAST_SIDES; + using OpenSHC::Map::LogicHelpers::RF_SOUTH_SIDE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC0B0 + void TileMapState::computeTileCliffEdgeFlags(int tile, int x, int y) + { + int const height = this->HeightLayer[tile]; + int lowest = height; + int highest = height; + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_MULTIPLAYER) { + return; + } + + int heights[CD_UPPER_LIMIT]; + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.field_0x372c); i++) { + XYPair offset; + offset.x = DAT_TerrainDefinedData::instance.field_0x372c[i].x; + offset.y = DAT_TerrainDefinedData::instance.field_0x372c[i].y; + uint const neighbourY = offset.y + y; + uint const neighbourX = offset.x + x; + heights[i] = height; + if (neighbourX > MC_MAP_XY_LIMIT_INCLUSIVE || neighbourY > MC_MAP_XY_LIMIT_INCLUSIVE + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[neighbourY * MC_MAP_XY_LIMIT + neighbourX] + == 0) { + continue; + } + int const neighbour + = DAT_ViewportRenderState::instance.translationMatrix[neighbourY].addXgetTile + offset.x + x; + if ((this->LogicLayer[neighbour] & L_RIVER) == 0) { + continue; + } + heights[i] = this->HeightLayer[neighbour]; + if (heights[i] < lowest) { + lowest = heights[i]; + } else if (heights[i] > highest) { + highest = heights[i]; + } + } + + this->Logic2Layer[tile] &= (L2_BEACH | L2_OASIS_GRASS | L2_PLATEAU_HIGH); + byte const flags = this->Logic2Layer[tile]; + if (lowest < height) { + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { + if (heights[CD_EAST] < height && heights[CD_SOUTH] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_AND_EAST_SIDES; + } else if (heights[CD_SOUTH] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_SIDE; + } else if (heights[CD_EAST] < height) { + this->Logic2Layer[tile] = flags | RF_EAST_SIDE; + } + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { + if (heights[CD_NORTH] < height && heights[CD_WEST] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_AND_EAST_SIDES; + } else if (heights[CD_NORTH] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_SIDE; + } else if (heights[CD_WEST] < height) { + this->Logic2Layer[tile] = flags | RF_EAST_SIDE; + } + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { + if (heights[CD_SOUTH] < height && heights[CD_WEST] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_AND_EAST_SIDES; + } else if (heights[CD_WEST] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_SIDE; + } else if (heights[CD_SOUTH] < height) { + this->Logic2Layer[tile] = flags | RF_EAST_SIDE; + } + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { + if (heights[CD_NORTH] < height && heights[CD_EAST] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_AND_EAST_SIDES; + } else if (heights[CD_EAST] < height) { + this->Logic2Layer[tile] = flags | RF_SOUTH_SIDE; + } else if (heights[CD_NORTH] < height) { + this->Logic2Layer[tile] = flags | RF_EAST_SIDE; + } + } + } else if (highest > height) { + if (highest > height + 16) { + this->Logic2Layer[tile] = flags | L2_STONES_OR_DRIVEN_SANDUnk; + } else { + this->Logic2Layer[tile] = flags | L2_THICK_SCRUB; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/computeTileLuminescence.cpp b/src/OpenSHC/Map/TileMapState/computeTileLuminescence.cpp new file mode 100644 index 0000000000..6f6aa5d58e --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/computeTileLuminescence.cpp @@ -0,0 +1,284 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::CD_EAST; + using OpenSHC::Map::Enums::CD_NORTH; + using OpenSHC::Map::Enums::CD_NORTHEAST; + using OpenSHC::Map::Enums::CD_NORTHWEST; + using OpenSHC::Map::Enums::CD_SOUTH; + using OpenSHC::Map::Enums::CD_SOUTHEAST; + using OpenSHC::Map::Enums::CD_SOUTHWEST; + using OpenSHC::Map::Enums::CD_WEST; + using OpenSHC::Map::Enums::MO_EAST; + using OpenSHC::Map::Enums::MO_NORTH; + using OpenSHC::Map::Enums::MO_SOUTH; + using OpenSHC::Map::Enums::MO_WEST; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_TREE; + using OpenSHC::Map::LogicHelpers::L_TREE_VARIATION; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F7A80 + void TileMapState::computeTileLuminescence(int tile, int y) + { + uint logic = this->LogicLayer[tile]; + int diagonal = 0; + int opposite = 0; + int slope = 0; + int shade = 2; + int alongShade = 2; + int acrossShade = 2; + int along = 0; + int across = 0; + int high = 0; + if ((logic & (L_BORDER | L_BORDER_EDGE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + return; + } + + switch (this->mapOrientation) { + case MO_NORTH: + diagonal = CD_SOUTHWEST; + opposite = CD_NORTHEAST; + along = CD_SOUTH; + across = CD_WEST; + break; + case MO_EAST: + diagonal = CD_NORTHWEST; + opposite = CD_SOUTHEAST; + along = CD_WEST; + across = CD_NORTH; + break; + case MO_SOUTH: + diagonal = CD_NORTHEAST; + opposite = CD_SOUTHWEST; + along = CD_NORTH; + across = CD_EAST; + break; + case MO_WEST: + diagonal = CD_SOUTHEAST; + opposite = CD_NORTHWEST; + along = CD_EAST; + across = CD_SOUTH; + } + + int ownHeight = this->HeightLayer[tile]; + int rayY = y; + int stage = 0; + if ((logic & L_TREE) != 0) { + stage = MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getTreeGrowthTargetStage, + &DAT_LandscapeState::instance)(this->OrganismLayer[tile]); + } else if ((logic & L_TREE_VARIATION) != 0) { + stage = 5; + } + if (stage > 2) { + shade = stage; + } + + int rayTile = tile; + for (int i = 0; i < 5; i++) { + rayTile += this->directionTranslationMatrix[rayY][diagonal]; + rayY += DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[diagonal].int_.yOffset; + if ((this->LogicLayer[rayTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + break; + } + if ((this->LogicLayer[rayTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + int building = this->BuildingLayer[rayTile]; + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag3, + &DAT_BuildingsState::instance)(building) + == 0) { + high = this->HeightLayer[rayTile] + + max(16, + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + &DAT_BuildingsState::instance)(building)); + } + } else { + high = this->HeightLayer[rayTile]; + } + if ((this->LogicLayer[rayTile] & L_TREE) != 0) { + high += MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getTreeGrowthTargetStage, + &DAT_LandscapeState::instance)(this->OrganismLayer[rayTile]) + * 7; + } else if ((this->LogicLayer[rayTile] & L_TREE_VARIATION) != 0) { + high += 40; + } + int rise = high - ownHeight; + int lit; + if (rise <= 0) { + lit = 2; + } else if (rise > 18) { + lit = 7 - i; + } else if (rise > 14) { + lit = 6 - i; + } else if (rise > 10) { + lit = 5 - i; + } else if (rise > 6) { + lit = 4 - i; + } else if (rise > 2) { + lit = 3 - i; + } else { + lit = 0; + } + if (lit > shade) { + shade = lit; + } + } + + int alongTile = this->directionTranslationMatrix[y][along] + tile; + int alongY = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[along].int_.yOffset + y; + for (int reach = 4; reach > -1; reach--) { + if ((this->LogicLayer[alongTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + break; + } + if ((this->LogicLayer[alongTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + int building = this->BuildingLayer[alongTile]; + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag3, + &DAT_BuildingsState::instance)(building) + == 0) { + high = this->HeightLayer[alongTile] + + max(16, + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + &DAT_BuildingsState::instance)(building)); + } + } else { + high = this->HeightLayer[alongTile]; + } + if ((this->LogicLayer[alongTile] & L_TREE) != 0) { + high += MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getTreeGrowthTargetStage, + &DAT_LandscapeState::instance)(this->OrganismLayer[alongTile]) + * 7; + } else if ((this->LogicLayer[alongTile] & L_TREE_VARIATION) != 0) { + high += 40; + } + int rise = high - ownHeight; + int lit; + if (rise <= 0) { + lit = 2; + } else if (rise > 18) { + lit = reach + 1; + } else if (rise > 12) { + lit = reach; + } else if (rise > 6) { + lit = reach - 1; + } else { + lit = 0; + } + if (lit > alongShade) { + alongShade = lit; + } + alongTile += this->directionTranslationMatrix[alongY][diagonal]; + alongY += DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[diagonal].int_.yOffset; + } + + int acrossTile = this->directionTranslationMatrix[y][across] + tile; + int acrossY = DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[across].int_.yOffset + y; + for (int reach = 4; reach > -1; reach--) { + if ((this->LogicLayer[acrossTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + break; + } + if ((this->LogicLayer[acrossTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + int building = this->BuildingLayer[acrossTile]; + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag3, + &DAT_BuildingsState::instance)(building) + == 0) { + high = this->HeightLayer[acrossTile] + + max(16, + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + &DAT_BuildingsState::instance)(building)); + } + } else { + high = this->HeightLayer[acrossTile]; + } + if ((this->LogicLayer[acrossTile] & L_TREE) != 0) { + high += MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::getTreeGrowthTargetStage, + &DAT_LandscapeState::instance)(this->OrganismLayer[acrossTile]) + * 7; + } else if ((this->LogicLayer[acrossTile] & L_TREE_VARIATION) != 0) { + high += 40; + } + int rise = high - ownHeight; + int lit; + if (rise <= 0) { + lit = 2; + } else if (rise > 18) { + lit = reach + 1; + } else if (rise > 12) { + lit = reach; + } else if (rise > 6) { + lit = reach - 1; + } else { + lit = 0; + } + if (lit > acrossShade) { + acrossShade = lit; + } + acrossTile += this->directionTranslationMatrix[acrossY][diagonal]; + acrossY += DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[diagonal].int_.yOffset; + } + + if (acrossShade + alongShade - 4 > shade - 2) { + int sum = acrossShade + alongShade - 2; + shade = sum < 7 ? sum : 7; + } + if (shade == 2) { + int diagonalTile = this->directionTranslationMatrix[y][diagonal] + tile; + if ((this->LogicLayer[diagonalTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + high = ownHeight; + } else { + if ((this->LogicLayer[diagonalTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + int building = this->BuildingLayer[diagonalTile]; + if (MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag3, + &DAT_BuildingsState::instance)(building) + == 0) { + high = this->HeightLayer[diagonalTile] + + max(16, + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + &DAT_BuildingsState::instance)(building)); + } + } else { + high = this->HeightLayer[diagonalTile]; + } + } + int oppositeTile = this->directionTranslationMatrix[y][opposite] + tile; + int darkSide; + if ((this->LogicLayer[oppositeTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + darkSide = ownHeight; + } else { + darkSide = this->HeightLayer[oppositeTile]; + } + if (high < ownHeight - 4) { + slope = 1; + } + if (darkSide > ownHeight + 4) { + slope += 1; + } + if ((this->LogicLayer[tile] & L_MOAT) == 0) { + if (slope == 1) { + shade = 1; + } else if (slope == 2) { + shade = 0; + } + } + } + this->LuminesenceLayer[tile] = shade; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/createPlateau.cpp b/src/OpenSHC/Map/TileMapState/createPlateau.cpp new file mode 100644 index 0000000000..7ad1718c11 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/createPlateau.cpp @@ -0,0 +1,87 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/TileMapState/NeighbourFlagsGlobalAsm.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_HIGH; + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_MEDIUM; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + 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_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00501F50 + void TileMapState::createPlateau(int tile, int y, int brush, Logic2 plateauType) + { + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[brush]; + int maxHeightInBrush = 0; + int const baseTile = tile; + int const baseY = y; + + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, &tile, &y, baseTile, baseY); + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) == 0 + && this->HeightLayer[tile] > maxHeightInBrush) { + maxHeightInBrush = this->HeightLayer[tile]; + } + } + + tile = baseTile; + y = baseY; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, &tile, &y, baseTile, baseY); + int const brushTile = tile; + if ((this->LogicLayer[brushTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + continue; + } + if ((this->LogicLayer[brushTile] & (L_SEA | L_BUILDING | L_KEEP_NON_MANOR_HOUSE | L_MARSH | L_MOAT)) != 0) { + continue; + } + if (this->BuildingLayer[brushTile] != 0) { + continue; + } + if ((this->LogicLayer[brushTile] + & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_MOAT_DUG_OR_PLANNED | L_KEEP_NON_MANOR_HOUSE | L_MOAT)) + != 0) { + continue; + } + int& logic = this->LogicLayer[brushTile]; + logic &= ~L_ROCKY; + if (plateauType == L2_PLATEAU_MEDIUM) { + this->HeightLayer[brushTile] = 80; + } else if (plateauType == L2_PLATEAU_HIGH) { + this->HeightLayer[brushTile] = 130; + } + byte& height = this->HeightLayer[brushTile]; + this->DefaultHeightLayer[brushTile] = height; + if ((this->LogicLayer[brushTile] & L_RIVER) != 0) { + height -= 8; + } + int const brushY = y; + this->Logic2Layer[brushTile] = plateauType; + this->DAT_SomeTile = brushTile; + this->DAT_SomeY = brushY; + + MACRO_MARK_CHANGED_NEIGHBOURS_GLOBAL() + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(brushY, brushTile); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/createWaterForDrawBridge.cpp b/src/OpenSHC/Map/TileMapState/createWaterForDrawBridge.cpp new file mode 100644 index 0000000000..d808798bf3 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/createWaterForDrawBridge.cpp @@ -0,0 +1,50 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT; + + // FUNCTION: STRONGHOLDCRUSADER 0x00515C80 + void TileMapState::createWaterForDrawBridge(int buildingID) + { + Buildings::Building const& building = DAT_BuildingsState::instance.buildings[buildingID]; + int const xPosition = building.x; + int const yPosition = building.y; + int const widthOrHeight = building.widthOrHeight; + int buildingSizeTileIndex = 0; + int const* drawbridgeMapping + = DAT_TerrainDefinedData::instance.DrawbridgeOrientationMapping[building.buildingVariation / 2]; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[yPosition + this->buildingY].addXgetTile + + this->buildingX + xPosition; + if (*drawbridgeMapping != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::createMoatData, this)( + DAT_BuildingsState::instance.buildings[buildingID].owner, this->buildingX + xPosition, + yPosition + this->buildingY, TRUE); + this->LogicLayer[tile] &= ~L_MOAT; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMoatVisualStateAtTile, this)(tile, 0); + this->HeightLayer[tile] = 0; + } + buildingSizeTileIndex++; + drawbridgeMapping++; + } while (buildingSizeTileIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateBuildingGraphicsLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(widthOrHeight + 6, xPosition, yPosition); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/demolishBuildingsInKeepsConstructionFootprint.cpp b/src/OpenSHC/Map/TileMapState/demolishBuildingsInKeepsConstructionFootprint.cpp new file mode 100644 index 0000000000..ced7ee0e4c --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/demolishBuildingsInKeepsConstructionFootprint.cpp @@ -0,0 +1,115 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::BuildingLogicalState; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FA760 + void TileMapState::demolishBuildingsInKeepsConstructionFootprint( + int playerID, int x, int y, BuildingType buildingType, int size, int orientation, int height) + { + int index = 0; + int const keepX = x; + int const keepY = y; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, size); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (this->BuildingLayer[tile] != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(this->BuildingLayer[tile]); + } + index++; + } while (index < this->constructionTileCount); + + buildingType = (BuildingType)((short)buildingType - OpenSHC::Map::Buildings::BT_MANORHOUSE); + { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[buildingType][0][0].y + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[buildingType][0][0].x + x; + if (this->BuildingLayer[tile] != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(this->BuildingLayer[tile]); + } + } + + { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[buildingType][0][1].y + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[buildingType][0][1].x + x; + if (this->BuildingLayer[tile] != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(this->BuildingLayer[tile]); + } + } + + { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[buildingType][0][2].y + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[buildingType][0][2].x + x; + if (this->BuildingLayer[tile] != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(this->BuildingLayer[tile]); + } + } + + x += DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[buildingType][0].xOffset; + y += DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[buildingType][0].yOffset; + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 7); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (this->BuildingLayer[tile] != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(this->BuildingLayer[tile]); + } + index++; + } while (index < this->constructionTileCount); + + x = keepX + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[buildingType][0].xOffset; + y = keepY + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[buildingType][0].yOffset; + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 5); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (this->BuildingLayer[tile] != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(this->BuildingLayer[tile]); + } + index++; + } while (index < this->constructionTileCount); + + for (int buildingID = 1; buildingID < countof(DAT_BuildingsState::instance.buildings); buildingID++) { + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState + == OpenSHC::Map::Buildings::BLS_REMOVE) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/determineBuildingPlacementRotation.cpp b/src/OpenSHC/Map/TileMapState/determineBuildingPlacementRotation.cpp new file mode 100644 index 0000000000..d324898659 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/determineBuildingPlacementRotation.cpp @@ -0,0 +1,156 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +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::Enums::CD_EAST; + using OpenSHC::Map::Enums::CD_NORTH; + using OpenSHC::Map::Enums::CD_NORTHEAST; + using OpenSHC::Map::Enums::CD_NORTHWEST; + using OpenSHC::Map::Enums::CD_SOUTH; + using OpenSHC::Map::Enums::CD_SOUTHEAST; + using OpenSHC::Map::Enums::CD_SOUTHWEST; + using OpenSHC::Map::Enums::CD_UPPER_LIMIT; + using OpenSHC::Map::Enums::CD_WEST; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FA000 + void TileMapState::determineBuildingPlacementRotation(int x, int y) + { + int volatile wallTileCount = 0; + this->field_0x554944 = 128; + this->uiBuildingRotation = CD_UPPER_LIMIT; + if (this->buildingPlacementFail) { + return; + } + + int walls[countof(DAT_TerrainDefinedData::instance.footprintSideOffsets)]; + int* volatile wall = walls; + for (int rotation = 0; rotation < countof(walls); rotation++, wall++) { + *wall = 0; + { + int const tileY = DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][0].y + y; + if ((uint)(DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][0].x + x) + <= MC_MAP_XY_LIMIT_INCLUSIVE + && tileY >= 0 && tileY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][0].x + x] + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][0].x + x] + & L_WALL_OR_GATEHOUSE) + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][0].x + x] + & (L_STOCKPILEUnk | L_STAIRS)) + == 0) { + wallTileCount++; + *wall = 1; + } + } + { + int const tileY = DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][1].y + y; + if ((uint)(DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][1].x + x) + <= MC_MAP_XY_LIMIT_INCLUSIVE + && tileY >= 0 && tileY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][1].x + x] + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][1].x + x] + & L_WALL_OR_GATEHOUSE) + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][1].x + x] + & (L_STOCKPILEUnk | L_STAIRS)) + == 0) { + *wall += 1; + wallTileCount++; + } + } + { + int const tileY = DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][2].y + y; + if ((uint)(DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][2].x + x) + <= MC_MAP_XY_LIMIT_INCLUSIVE + && tileY >= 0 && tileY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][2].x + x] + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][2].x + x] + & L_WALL_OR_GATEHOUSE) + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][2].x + x] + & (L_STOCKPILEUnk | L_STAIRS)) + == 0) { + *wall += 1; + wallTileCount++; + } + } + { + int const tileY = DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][3].y + y; + if ((uint)(DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][3].x + x) + <= MC_MAP_XY_LIMIT_INCLUSIVE + && tileY >= 0 && tileY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][3].x + x] + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][3].x + x] + & L_WALL_OR_GATEHOUSE) + != 0 + && (this->LogicLayer[DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile + + DAT_TerrainDefinedData::instance.footprintSideOffsets[rotation][3].x + x] + & (L_STOCKPILEUnk | L_STAIRS)) + == 0) { + *wall += 1; + wallTileCount++; + } + } + } + + this->uiBuildingRotation = CD_UPPER_LIMIT; + if (walls[0] == 4 && walls[3] == 4) { + this->uiBuildingRotation = CD_NORTHWEST; + } else if (walls[0] == 4 && walls[1] == 4) { + this->uiBuildingRotation = CD_NORTHEAST; + } else if (walls[2] == 4 && walls[3] == 4) { + this->uiBuildingRotation = CD_SOUTHWEST; + } else if (walls[2] == 4 && walls[1] == 4) { + this->uiBuildingRotation = CD_SOUTHEAST; + } else if (walls[0] == 4) { + this->uiBuildingRotation = CD_NORTH; + } else if (walls[1] == 4) { + this->uiBuildingRotation = CD_EAST; + } else if (walls[2] == 4) { + this->uiBuildingRotation = CD_SOUTH; + } else if (walls[3] == 4) { + this->uiBuildingRotation = CD_WEST; + } + + int relative; + if (this->uiBuildingRotation != CD_UPPER_LIMIT) { + relative = this->uiBuildingRotation - this->mapOrientation; + if (relative < 0) { + this->field_0x554944 = (relative + CD_UPPER_LIMIT) * 16; + return; + } + } else { + relative = CD_UPPER_LIMIT; + } + this->field_0x554944 = relative * 16; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/eraseAreaWithBrush.cpp b/src/OpenSHC/Map/TileMapState/eraseAreaWithBrush.cpp new file mode 100644 index 0000000000..69e2bbdc7a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/eraseAreaWithBrush.cpp @@ -0,0 +1,134 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.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_BORDER_EDGE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508EC0 + void TileMapState::eraseAreaWithBrush(int x, int y, uint brush) + { + if (x < 0 || x > MC_MAP_XY_LIMIT_INCLUSIVE || y < 0 || y > MC_MAP_XY_LIMIT_INCLUSIVE) { + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { + return; + } + + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[brush]; + int const baseTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int const savedY = y; + int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, savedY); + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + break; + } + int const organism = this->OrganismLayer[tile]; + if (organism != 0) { + if (organism >= countof(DAT_LandscapeState::instance.trees)) { + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeRock, DAT_LandscapeState::ptr)( + organism - countof(DAT_LandscapeState::instance.trees)); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeTree, DAT_LandscapeState::ptr)(organism); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(3, x, y); + } + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + } + } + + y = savedY; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, savedY); + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + break; + } + uint const brushY = y; + this->placementOnWall = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateBuildingPlacementAtTile, this)(0, x, brushY); + if (this->buildingPlacementFail != FALSE) { + continue; + } + if (this->placementOnWall == 0) { + int const targetID = this->cursorTargetID; + if (targetID == -1) { + continue; + } + int const owner = DAT_BuildingsState::instance.buildings[targetID].owner; + if (targetID + == DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id + && DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id + != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuildingAndLinkedDuplicates, + DAT_BuildingsState::ptr)(DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id); + } + if (DAT_BuildingsState::instance.buildings[targetID].buildingType + == OpenSHC::Map::Buildings::BT_STOCKPILE + && DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id + != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuildingAndLinkedDuplicates, + DAT_BuildingsState::ptr)(DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id); + } + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuildingAndLinkedDuplicates, + DAT_BuildingsState::ptr)(this->cursorTargetID); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::spawnEraserTileEffect, this)( + 0, DAT_ViewportRenderState::instance.translationMatrix[brushY].addXgetTile + x); + } + } + + y = savedY; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, savedY); + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + return; + } + for (int unit = DAT_TileMapState::instance.UnitLayer[tile]; unit != 0; + unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + DAT_UnitsState::instance.units[unit].logicalState = OpenSHC::Map::Units::ULS_REMOVE; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/evaluateBuildingPlacementAtCursor.cpp b/src/OpenSHC/Map/TileMapState/evaluateBuildingPlacementAtCursor.cpp new file mode 100644 index 0000000000..c0a2427702 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/evaluateBuildingPlacementAtCursor.cpp @@ -0,0 +1,231 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingFailReasonEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingPlacementFailState.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.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::Buildings::Enums::BPFS_BLOCKED; + using OpenSHC::Map::Buildings::Enums::BPFS_NONE; + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Map::Buildings::BuildingFailReasonEnum; + using OpenSHC::Map::LogicHelpers::MD_DESTROY_PENDING; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; + + // FUNCTION: STRONGHOLDCRUSADER 0x00504A30 + void TileMapState::evaluateBuildingPlacementAtCursor(int playerID, uint x, uint y) + { + int moatTile = 0; + bool const valid = x <= MC_MAP_XY_LIMIT_INCLUSIVE && y <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] != 0; + if (!valid) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + uint anchorX = x; + uint anchorY = y; + this->buildingPlacementFail = BPFS_NONE; + int wallTile = DAT_ViewportRenderState::instance.viewportState.cursorWallTile; + if (DAT_ViewportRenderState::instance.viewportState.field_0x3c != 0) { + moatTile = DAT_ViewportRenderState::instance.viewportState.cursorTile; + this->savedCursorTile = DAT_ViewportRenderState::instance.viewportState.cursorTile; + } + + int buildingID; + if (this->flatViewToggleValue1 != 0) { + buildingID = this->BuildingLayer[DAT_ViewportRenderState::instance.viewportState.mouseFlatTile]; + wallTile = 0; + if ((DAT_TileMapState::instance.LogicLayer[DAT_ViewportRenderState::instance.viewportState.mouseFlatTile] + & L_WALL_OR_GATEHOUSE) + != 0 + && ((DAT_TileMapState::instance + .LogicLayer[DAT_ViewportRenderState::instance.viewportState.mouseFlatTile] + & L_STOCKPILEUnk) + == 0 + || buildingID == 0)) { + wallTile = DAT_ViewportRenderState::instance.viewportState.mouseFlatTile; + DAT_ViewportRenderState::instance.viewportState.cursorWallTile = wallTile; + } + } else { + buildingID = DAT_ViewportRenderState::instance.viewportState.mouseRayBuildingID; + } + if (buildingID != 0) { + anchorX = DAT_BuildingsState::instance.buildings[buildingID].x; + anchorY = DAT_BuildingsState::instance.buildings[buildingID].y; + } + + int const enemyDistance + = DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY ? 15 : 30; + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT + && MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)(playerID, anchorX, anchorY, enemyDistance)) { + this->demolishBlocked = 1; + this->buildingPlacementFail = BPFS_BLOCKED; + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_20; + if (buildingID != 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].owner == playerID || playerID == 0) { + return; + } + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE; + return; + } + if (wallTile > 0) { + if ((this->LogicLayer[wallTile] & L_WALL_OR_GATEHOUSE) == 0 + || (this->WallOwnerLayer[wallTile] & WO_OWNER_MASK) + 1 == playerID) { + return; + } + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE; + return; + } + if (moatTile > 0 && (this->LogicLayer[moatTile] & L_MOAT) != 0) { + int const moatID + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)(moatTile); + if (moatID == 0) { + return; + } + if (DAT_GameState::instance.mapAndTime.playerTeams[this->moats[moatID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + return; + } + } + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BFRE_DEFAULT_CANT_PLACE_THAT_THERE; + return; + } + + if (DAT_ViewportRenderState::instance.viewportState.somePitchDitchID != 0) { + if (this->pitchDitches[DAT_ViewportRenderState::instance.viewportState.somePitchDitchID].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + this->cursorTargetID = -DAT_ViewportRenderState::instance.viewportState.somePitchDitchID; + return; + } + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + + if (buildingID <= 0 + || (DAT_BuildingsState::instance.buildings[buildingID].owner != playerID && playerID != 0)) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + + bool checkMoat = true; + if (wallTile > 0) { + if ((this->LogicLayer[wallTile] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[wallTile] & L_STOCKPILEUnk) != 0) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + if ((this->LogicLayer[wallTile] & L_WALL_OR_GATEHOUSE) != 0 && this->BuildingLayer[wallTile] == 0 + && !this->placementOnMoat) { + if ((this->WallOwnerLayer[wallTile] & WO_OWNER_MASK) + 1 != playerID) { + return; + } + this->buildingPlacementFail = BPFS_NONE; + this->placementOnWall = TRUE; + if ((this->MiscDisplayLayer[wallTile] & MD_DESTROY_PENDING) != 0) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + checkMoat = false; + } + } + if (checkMoat) { + if (moatTile > 0 && (this->LogicLayer[moatTile] & L_MOAT) != 0 && buildingID == 0) { + if (this->placementOnWall) { + this->buildingPlacementFail = BPFS_BLOCKED; + } else { + int const moatID + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)(moatTile); + if (moatID == 0) { + return; + } + if (DAT_GameState::instance.mapAndTime.playerTeams[this->moats[moatID].owner] + != DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + return; + } + this->buildingPlacementFail = BPFS_NONE; + this->placementOnMoat = TRUE; + if ((this->MiscDisplayLayer[moatTile] & MD_DESTROY_PENDING) != 0) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + wallTile = moatTile; + } + } else if (this->placementOnWall || this->placementOnMoat) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + } + + if (wallTile > 0 && this->UnitLayer[wallTile] != 0) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + if (buildingID != 0) { + bool const isRegularGame = DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT; + if (isRegularGame) { + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_UNKNOWN1: + case OpenSHC::Map::Buildings::BT_MANORHOUSE: + case OpenSHC::Map::Buildings::BT_STONEKEEP: + case OpenSHC::Map::Buildings::BT_STRONGHOLD: + case OpenSHC::Map::Buildings::BT_SIGNPOST: + case OpenSHC::Map::Buildings::BT_CAMPGROUND: + case OpenSHC::Map::Buildings::BT_KEEPDOOR_LEFT: + case OpenSHC::Map::Buildings::BT_KEEPDOOR_RIGHT: + case OpenSHC::Map::Buildings::BT_KEEPDOOR: + case OpenSHC::Map::Buildings::BT_POND: + this->buildingPlacementFail = BPFS_BLOCKED; + } + } else if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT) { + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_SIGNPOST) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + } + if (buildingID < 0) { + this->cursorTargetID = buildingID; + return; + } + } + + if ((this->LogicLayer[DAT_BuildingsState::instance.buildings[buildingID].currentTilePositionAdjusted] + & (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_KILLINGPIT + && !this->placementOnWall && !this->placementOnMoat) { + this->buildingPlacementFail = BPFS_BLOCKED; + } + this->cursorTargetID = buildingID; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/findNearestFriendlyMoatTileForDigging.cpp b/src/OpenSHC/Map/TileMapState/findNearestFriendlyMoatTileForDigging.cpp new file mode 100644 index 0000000000..d61220122a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/findNearestFriendlyMoatTileForDigging.cpp @@ -0,0 +1,97 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Enums/MoatStage.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::MS_DUG; + using OpenSHC::Map::Enums::MS_PLANNED; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED; + + // FUNCTION: STRONGHOLDCRUSADER 0x005111D0 + BOOLEnum TileMapState::findNearestFriendlyMoatTileForDigging(int playerID, int unitID, MoatStageInt stage) + { + int best = 1000; + int bestMoatID = -1; + int const unitX = DAT_UnitsState::instance.units[unitID].x; + int const unitY = DAT_UnitsState::instance.units[unitID].y; + int const area + = this->PathConnectionLayer[DAT_ViewportRenderState::instance.translationMatrix[unitY].addXgetTile + unitX]; + for (int moatID = 0; moatID < this->currentMoatCount; moatID++) { + if (stage == MS_PLANNED) { + if (DAT_GameState::instance.mapAndTime.playerTeams[this->moats[moatID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + } else { + continue; + } + } else if (stage == MS_DUG) { + if (DAT_GameState::instance.mapAndTime.playerTeams[this->moats[moatID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + continue; + } + } + if (this->moats[moatID].stage != stage) { + continue; + } + if (this->BuildingLayer[this->moats[moatID].tile] != 0 && this->moats[moatID].zeroOrTwo == 0) { + continue; + } + int const tile = this->moats[moatID].tile; + if ((this->LogicLayer[tile] & (L_MOAT_DUG_OR_PLANNED | L_MOAT)) == 0) { + continue; + } + if (this->moats[moatID].someCountDown >= 100) { + continue; + } + if (this->UnitLayer[tile] != 0 + && DAT_UnitsState::instance.units[this->UnitLayer[tile]].someUnitStat4 == 0) { + continue; + } + if (stage == MS_DUG + && !MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::findTileInSameAreaAndNoTooHeightDifference, + this)(area, tile, this->moats[moatID].y)) { + continue; + } + + int const pathCost + = DAT_TileMapState::instance.SEC_PathfindingCostTileMap1105[this->moats[moatID].owner][tile]; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(unitX, unitY, this->moats[moatID].x, this->moats[moatID].y); + int score = DAT_DirectionAlgorithmState::instance.distanceHigh; + int fromTarget; + if (DAT_UnitsState::instance.units[unitID].targetX > 0) { + fromTarget = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult, + DAT_DirectionAlgorithmState::ptr)(DAT_UnitsState::instance.units[unitID].targetX, + DAT_UnitsState::instance.units[unitID].targetY, this->moats[moatID].x, this->moats[moatID].y); + } else { + fromTarget = 0; + } + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] == -1) { + score += pathCost * 10; + } + score += fromTarget / 2 + this->moats[moatID].someCountDown; + if (score < best) { + best = score; + bestMoatID = moatID; + } + } + + if (bestMoatID != 0) { + this->moats[bestMoatID].someCountDown += 20; + } + return bestMoatID; + } +} +} diff --git a/src/OpenSHC/Map/TileMapState/floodMoatUnderRemovedBuilding.cpp b/src/OpenSHC/Map/TileMapState/floodMoatUnderRemovedBuilding.cpp new file mode 100644 index 0000000000..407f8dafc5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/floodMoatUnderRemovedBuilding.cpp @@ -0,0 +1,46 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_MOAT; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508910 + void TileMapState::floodMoatUnderRemovedBuilding(int buildingID) + { + int const xPosition = DAT_BuildingsState::instance.buildings[buildingID].x; + int const yPosition = DAT_BuildingsState::instance.buildings[buildingID].y; + uint const widthOrHeight = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; + int const variation = DAT_BuildingsState::instance.buildings[buildingID].buildingVariation / 2; + int buildingSizeTileIndex = 0; + int const* drawbridgeMapping = DAT_TerrainDefinedData::instance.DrawbridgeOrientationMapping[variation]; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + yPosition].addXgetTile + + this->buildingX + xPosition; + if (*drawbridgeMapping != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)(tile) != 0) { + this->LogicLayer[tile] |= L_MOAT; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMoatVisualStateAtTile, this)(tile, 2); + } + buildingSizeTileIndex++; + drawbridgeMapping++; + } while (buildingSizeTileIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updateBuildingGraphicsLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(widthOrHeight + 6, xPosition, yPosition); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/generateDustClouds.cpp b/src/OpenSHC/Map/TileMapState/generateDustClouds.cpp new file mode 100644 index 0000000000..e5c7f759a0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/generateDustClouds.cpp @@ -0,0 +1,68 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" + +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Entities::EntityType; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC490 + void TileMapState::generateDustClouds() + { + int const seed = SEC_RNG::instance.currentNumber2; + MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + this->SEC_Section1052 += 1; + if (seed % 500 == this->SEC_Section1052 % 500) { + this->SEC_Section1053 = seed % 180; + } + if (seed % 1200 == this->SEC_Section1052 % 1200) { + this->SEC_Section1054 = seed % 180; + } + if (this->SEC_Section1053 != 0) { + this->SEC_Section1053 -= 1; + } + if (this->SEC_Section1054 != 0) { + this->SEC_Section1054 -= 1; + } + + for (int i = 0; i < this->temporaryTerrainTypeIndex; i++) { + if ((this->RandomLayer[this->temporaryTerrainTypeArray[i]] ^ seed) % 64 != this->SEC_Section1052 % 64) { + continue; + } + int const tileY = DAT_ViewportRenderState::instance + .tileTranslationMatrix_YComponent[this->temporaryTerrainTypeArray[i]]; + int const tileX = this->temporaryTerrainTypeArray[i] + - DAT_ViewportRenderState::instance.translationMatrix[tileY].addXgetTile; + int const variant = this->temporaryTerrainTypeBinaryArray[i]; + if (variant == 0) { + if (this->SEC_Section1054 == 0) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, 0, 0, + tileX * 8 + 4, tileY * 8 + 4, this->HeightLayer[this->temporaryTerrainTypeArray[i]], 0, 0, 0, + OpenSHC::Map::Entities::ET_DUST_CLOUD, variant); + } + } else if (this->SEC_Section1053 == 0) { + if (variant == 1) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, 0, 0, + tileX * 8 + 4, tileY * 8 + 4, this->HeightLayer[this->temporaryTerrainTypeArray[i]], 0, 0, 0, + OpenSHC::Map::Entities::ET_DUST_CLOUD, variant); + } else { + MACRO_CALL_MEMBER( + OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(0, 0, 0, + tileX * 8 + 4, tileY * 8 + 4, this->HeightLayer[this->temporaryTerrainTypeArray[i]], 0, 0, 0, + OpenSHC::Map::Entities::ET_DUST_CLOUD, 2); + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/getTotalHeightAt.cpp b/src/OpenSHC/Map/TileMapState/getTotalHeightAt.cpp new file mode 100644 index 0000000000..23793e03bf --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/getTotalHeightAt.cpp @@ -0,0 +1,170 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/OrganismLayerConstants.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" +#include "OpenSHC/Map/Rocks/Enums/RockType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.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::Enums::CD_EAST; + using OpenSHC::Map::Enums::CD_NORTH; + using OpenSHC::Map::Enums::CD_SOUTH; + using OpenSHC::Map::Enums::CD_UPPER_LIMIT; + using OpenSHC::Map::Enums::CD_WEST; + using OpenSHC::Map::Enums::OLC_ROCK_ID_OFFSET; + 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_ROCKY; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; + using OpenSHC::Map::Rocks::Enums::RT_3X3_A; + using OpenSHC::Map::Rocks::Enums::RT_4X4_A; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FFBA0 + int TileMapState::getTotalHeightAt(int tile, int playerID) + { + int extra = 0; + BOOLEnum exposed = FALSE; + uint const logic = this->LogicLayer[tile]; + if ((logic & L_KEEP_NON_MANOR_HOUSE) != 0) { + int const buildingID = this->BuildingLayer[tile]; + extra = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID); + for (int i = 0; i < CD_UPPER_LIMIT; i++) { + if (this->BuildingLayer[DAT_TileMapState::instance.directionTranslationMatrix[DAT_ViewportRenderState:: + instance.tileTranslationMatrix_YComponent[tile]][i] + + tile] + != buildingID) { + exposed = TRUE; + break; + } + } + if (playerID != 0 && DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + exposed = FALSE; + } + } else if ((logic & L_BUILDING) != 0) { + int const buildingID = this->BuildingLayer[tile]; + int const type = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + switch (type) { + case OpenSHC::Map::Buildings::BT_TOWER: + case OpenSHC::Map::Buildings::BT_TOWER1: + case OpenSHC::Map::Buildings::BT_TOWER2: + case OpenSHC::Map::Buildings::BT_TOWER3: + case OpenSHC::Map::Buildings::BT_TOWER4: + case OpenSHC::Map::Buildings::BT_TOWER5: + extra = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID) + + 20; + exposed = TRUE; + break; + case OpenSHC::Map::Buildings::BT_MANORHOUSE: + case OpenSHC::Map::Buildings::BT_STONEKEEP: + case OpenSHC::Map::Buildings::BT_STRONGHOLD: + case OpenSHC::Map::Buildings::BT_KEEPFOUR: + case OpenSHC::Map::Buildings::BT_KEEPFIVE: + extra = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID); + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_MANORHOUSE) { + for (int i = 0; i < CD_UPPER_LIMIT; i++) { + if (this->BuildingLayer[DAT_TileMapState::instance + .directionTranslationMatrix[DAT_ViewportRenderState::instance + .tileTranslationMatrix_YComponent[tile]][i] + + tile] + != buildingID) { + exposed = TRUE; + break; + } + } + } + break; + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + extra = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID); + exposed = TRUE; + break; + default: + extra = DAT_BuildingDefinedData::instance.BuildingHeights[type]; + break; + } + if (playerID != 0 && DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + exposed = FALSE; + } + } else if ((logic & L_ROCKY) != 0 && (logic & L_WALL_OR_GATEHOUSE) == 0) { + int organism = this->OrganismLayer[tile]; + if (organism >= OLC_ROCK_ID_OFFSET) { + organism -= OLC_ROCK_ID_OFFSET; + if (DAT_LandscapeState::instance.rocks[organism].type >= RT_4X4_A) { + extra = 70; + } else if (DAT_LandscapeState::instance.rocks[organism].type >= RT_3X3_A) { + extra = 50; + } + } + if (playerID != 0 && (this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 != playerID) { + exposed = FALSE; + } + } else if ((logic & L_CRENEL_VARIATIONUnk) != 0) { + extra = 20; + exposed = TRUE; + if (playerID != 0 && (this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 != playerID) { + exposed = FALSE; + } + } else if ((logic & L_CRENEL) != 0) { + extra = 10; + exposed = TRUE; + if (playerID != 0 && (this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 != playerID) { + exposed = FALSE; + } + } else if (this->BuildingLayer[tile] != 0) { + int const buildingID = this->BuildingLayer[tile]; + extra = 30; + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSESMALL) { + int first; + int second; + if (DAT_BuildingsState::instance.buildings[buildingID].buildingVariation == 80) { + first = CD_EAST; + second = CD_WEST; + } else { + first = CD_NORTH; + second = CD_SOUTH; + } + int const tileY = DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile]; + if (this->BuildingLayer[DAT_TileMapState::instance.directionTranslationMatrix[tileY][first] + tile] + != buildingID) { + exposed = TRUE; + } + if (this->BuildingLayer[DAT_TileMapState::instance.directionTranslationMatrix[tileY][second] + tile] + != buildingID) { + exposed = TRUE; + } + } + if (playerID != 0 && DAT_BuildingsState::instance.buildings[buildingID].owner != playerID) { + exposed = FALSE; + } + } + + extra += this->HeightLayer[tile]; + if (exposed) { + return extra; + } + return -1 - extra; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isBuildingPlacementAllowedAtTile.cpp b/src/OpenSHC/Map/TileMapState/isBuildingPlacementAllowedAtTile.cpp new file mode 100644 index 0000000000..7a0e9f9b89 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isBuildingPlacementAllowedAtTile.cpp @@ -0,0 +1,229 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Synchrony/GameSynchronyState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingPlacementWarning.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingTilePlacementResult.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.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_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::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_PLAIN1_AND_FARM; + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_TREE; + using OpenSHC::Map::LogicHelpers::L_TREE_VARIATION; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; + + using OpenSHC::Map::Buildings::Enums::BPW_APPLE_FARM_TOO_HIGH; + using OpenSHC::Map::Buildings::Enums::BPW_CATTLE_FARM_TOO_HIGH; + using OpenSHC::Map::Buildings::Enums::BPW_HOPS_FARM_TOO_HIGH; + using OpenSHC::Map::Buildings::Enums::BPW_WHEAT_FARM_TOO_HIGH; + using OpenSHC::Map::Buildings::Enums::BTPR_ALLOWED; + using OpenSHC::Map::Buildings::Enums::BTPR_BLOCKED; + using OpenSHC::Map::Buildings::Enums::BTPR_OCCUPIED_BY_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9A60 + BuildingTilePlacementResult TileMapState::isBuildingPlacementAllowedAtTile( + int tile, int playerID, MappersEnum commandBuildingType, BOOLEnum ignoreFarmland) + { + uint const logic = this->LogicLayer[tile]; + int const building = this->BuildingLayer[tile]; + BOOLEnum onRock = FALSE; + BOOLEnum onMarsh = FALSE; + BOOLEnum onMoat = FALSE; + int height = this->HeightLayer[tile]; + if ((logic & L_WALL_OR_GATEHOUSE) != 0 && (this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 == playerID) { + switch (commandBuildingType) { + case OpenSHC::Commands::M_MAPPER_GATEHOUSE: + case OpenSHC::Commands::M_MAPPER_GATE_MAIN: + case OpenSHC::Commands::M_MAPPER_GATE_INNER: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD: + case OpenSHC::Commands::M_MAPPER_GATE_POSTERN: + case OpenSHC::Commands::M_MAPPER_TOWER1: + case OpenSHC::Commands::M_MAPPER_TOWER2: + case OpenSHC::Commands::M_MAPPER_TOWER3: + case OpenSHC::Commands::M_MAPPER_TOWER4: + case OpenSHC::Commands::M_MAPPER_TOWER5: + 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_GATE_STONE1A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE1B: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2B: + height = this->DefaultHeightLayer[tile]; + } + } + + if (this->buildingHeightLimit >= 0) { + if (height > this->buildingHeightLimit) { + if (commandBuildingType == OpenSHC::Commands::M_MAPPER_CATTLEFARM) { + this->placementWarning = BPW_CATTLE_FARM_TOO_HIGH; + } else if (commandBuildingType == OpenSHC::Commands::M_MAPPER_APPLEFARM) { + this->placementWarning = BPW_APPLE_FARM_TOO_HIGH; + } else if (commandBuildingType == OpenSHC::Commands::M_MAPPER_HOPSFARM) { + this->placementWarning = BPW_HOPS_FARM_TOO_HIGH; + } else if (commandBuildingType == OpenSHC::Commands::M_MAPPER_WHEATFARM) { + this->placementWarning = BPW_WHEAT_FARM_TOO_HIGH; + } + return BTPR_BLOCKED; + } + } else if (height < -this->buildingHeightLimit) { + return BTPR_BLOCKED; + } + if (height > this->buildingMaxHeightDifference + this->buildingMinHeight) { + return BTPR_BLOCKED; + } + if ((logic & L_PLAIN2_AND_PITCH) != 0 && commandBuildingType == OpenSHC::Commands::M_MAPPER_PITCH_DITCH) { + return BTPR_BLOCKED; + } + if (building != 0) { + return BTPR_OCCUPIED_BY_BUILDING; + } + + if (this->UnitLayer[tile] != 0) { + int const unitID = this->UnitLayer[tile]; + if (MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::isAIPlayer, DAT_GameSynchronyState::ptr)( + playerID)) { + if (DAT_UnitsState::instance.units[unitID].unitType == OpenSHC::Map::Units::UT_LORD) { + return BTPR_BLOCKED; + } + if (DAT_UnitsState::instance.units[unitID].isSelectable_OR_matchTime != 0 + && DAT_UnitsState::instance.units[unitID].owner != playerID) { + return BTPR_BLOCKED; + } + } else if (DAT_UnitsState::instance.units[unitID].unitType != OpenSHC::Map::Units::UT_CHICKEN) { + return BTPR_BLOCKED; + } + } + + if ((logic & L_SEA) != 0) { + return BTPR_BLOCKED; + } + if ((logic & (L_BORDER | L_BORDER_EDGE)) != 0) { + return BTPR_BLOCKED; + } + if ((logic & L_RIVER) != 0) { + return BTPR_BLOCKED; + } + if ((logic & L_WALL_OR_GATEHOUSE) != 0) { + if ((this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 != playerID) { + return BTPR_BLOCKED; + } + switch (commandBuildingType) { + case OpenSHC::Commands::M_MAPPER_GATEHOUSE: + case OpenSHC::Commands::M_MAPPER_GATE_MAIN: + case OpenSHC::Commands::M_MAPPER_GATE_INNER: + case OpenSHC::Commands::M_MAPPER_GATE_WOOD: + case OpenSHC::Commands::M_MAPPER_GATE_POSTERN: + case OpenSHC::Commands::M_MAPPER_TOWER1: + case OpenSHC::Commands::M_MAPPER_TOWER2: + case OpenSHC::Commands::M_MAPPER_TOWER3: + case OpenSHC::Commands::M_MAPPER_TOWER4: + case OpenSHC::Commands::M_MAPPER_TOWER5: + 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_GATE_STONE1A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE1B: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2A: + case OpenSHC::Commands::M_MAPPER_GATE_STONE2B: + break; + default: + return BTPR_BLOCKED; + } + } + if ((logic & L_PLAIN1_AND_FARM) != 0 && !ignoreFarmland) { + return BTPR_BLOCKED; + } + if ((logic & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + return BTPR_BLOCKED; + } + + if ((logic & (L_TREE | L_TREE_VARIATION)) != 0) { + int const organism = this->OrganismLayer[tile]; + if (organism != 0 && organism < 2000) { + switch (DAT_LandscapeState::instance.trees[organism].treeType) { + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_A: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_B: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_C: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_D: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_E: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_A: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_B: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_C: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_D: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_E: + case OpenSHC::Map::Trees::TT_SHRUB_PIPE_CACTUS: + case OpenSHC::Map::Trees::TT_SHRUB_SUCCULENT: + case OpenSHC::Map::Trees::TT_SHRUB_CYCAD: + case OpenSHC::Map::Trees::TT_SHRUB_PRICKLYPEAR: + break; + default: + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { + return BTPR_BLOCKED; + } + if (!MACRO_CALL_MEMBER(OpenSHC::Synchrony::GameSynchronyState_Func::isAIPlayer, + DAT_GameSynchronyState::ptr)(playerID)) { + return BTPR_BLOCKED; + } + } + } + } + + if ((logic & (L_FARM_FIELD_WHEAT | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY)) != 0 + && !ignoreFarmland) { + return BTPR_BLOCKED; + } + if ((logic & L_FORD) != 0) { + return BTPR_BLOCKED; + } + + if ((logic & L_ROCKY) != 0 && (logic & L_WALL_OR_GATEHOUSE) == 0) { + onRock = TRUE; + } + if ((logic & L_MARSH) != 0) { + onMarsh = TRUE; + } + if ((logic & L_MOAT) != 0) { + onMoat = TRUE; + } + if (onRock && this->buildingPlacementProperty_4 == 0) { + return BTPR_BLOCKED; + } + if (onMoat && this->buildingPlacementProperty_7 == 0) { + return BTPR_BLOCKED; + } + if (this->buildingPlacementProperty_6 != 2 && onMarsh && this->buildingPlacementProperty_6 == 0) { + return BTPR_BLOCKED; + } + return BTPR_ALLOWED; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isTileSuitableForBrushPlacement.cpp b/src/OpenSHC/Map/TileMapState/isTileSuitableForBrushPlacement.cpp new file mode 100644 index 0000000000..f583cd59cb --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isTileSuitableForBrushPlacement.cpp @@ -0,0 +1,83 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FBE70 + BOOLEnum TileMapState::isTileSuitableForBrushPlacement(int tile, uint x, uint y) + { + byte height = this->HeightLayer[tile]; + uint neighbourY = y - 1; + if (x <= MC_MAP_XY_LIMIT_INCLUSIVE && neighbourY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[neighbourY * MC_MAP_XY_LIMIT + x] != 0 + && (height - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y - 1].addXgetTile + x]) + > 0) { + return TRUE; + } + uint neighbourX = x + 1; + if (neighbourX <= MC_MAP_XY_LIMIT_INCLUSIVE && neighbourY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[neighbourY * MC_MAP_XY_LIMIT + neighbourX] + != 0 + && (height + - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y - 1].addXgetTile + x + 1]) + > 0) { + return TRUE; + } + neighbourX = x + 1; + if (neighbourX <= MC_MAP_XY_LIMIT_INCLUSIVE && y <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + neighbourX] != 0 + && (height - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x + 1]) + > 0) { + return TRUE; + } + neighbourY = y + 1; + if (neighbourX <= MC_MAP_XY_LIMIT_INCLUSIVE && neighbourY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[neighbourY * MC_MAP_XY_LIMIT + neighbourX] + != 0 + && (height + - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y + 1].addXgetTile + x + 1]) + > 0) { + return TRUE; + } + if (x <= MC_MAP_XY_LIMIT_INCLUSIVE && neighbourY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[neighbourY * MC_MAP_XY_LIMIT + x] != 0 + && (height - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y + 1].addXgetTile + x]) + > 0) { + return TRUE; + } + neighbourX = x - 1; + if (neighbourX <= MC_MAP_XY_LIMIT_INCLUSIVE && neighbourY <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[neighbourY * MC_MAP_XY_LIMIT + neighbourX] + != 0 + && (height + - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y + 1].addXgetTile + x - 1]) + > 0) { + return TRUE; + } + neighbourX = x - 1; + if (neighbourX <= MC_MAP_XY_LIMIT_INCLUSIVE && y <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + neighbourX] != 0 + && (height - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x - 1]) + > 0) { + return TRUE; + } + + if (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, DAT_ViewportRenderState::ptr)( + neighbourX, y - 1) + != FALSE + && (height + - this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[y - 1].addXgetTile + x - 1]) + > 0) { + return TRUE; + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isUnitBlockingSizeFiveFootprint.cpp b/src/OpenSHC/Map/TileMapState/isUnitBlockingSizeFiveFootprint.cpp new file mode 100644 index 0000000000..0d4269bd7b --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isUnitBlockingSizeFiveFootprint.cpp @@ -0,0 +1,37 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004FAEE0 + BOOLEnum TileMapState::isUnitBlockingSizeFiveFootprint(int buildingID) + { + int const buildingX = DAT_BuildingsState::instance.buildings[buildingID].x; + int const buildingY = DAT_BuildingsState::instance.buildings[buildingID].y; + int const variation = DAT_BuildingsState::instance.buildings[buildingID].buildingVariation / 2; + int buildingSizeTileIndex = 0; + int const* mapping = DAT_TerrainDefinedData::instance.field_0x21ec[variation]; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, 5); + if (*mapping == 0 + && this->UnitLayer[DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + buildingY] + .addXgetTile + + this->buildingX + buildingX] + != 0) { + return TRUE; + } + buildingSizeTileIndex++; + mapping++; + } while (buildingSizeTileIndex < this->constructionTileCount); + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/isValidCastleSiteLocation.cpp b/src/OpenSHC/Map/TileMapState/isValidCastleSiteLocation.cpp new file mode 100644 index 0000000000..e0ae6a6312 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/isValidCastleSiteLocation.cpp @@ -0,0 +1,105 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.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_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 0x005024F0 + BOOLEnum TileMapState::isValidCastleSiteLocation(int x, int y, MappersEnum commandBuildingType) + { + int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int const baseTile = tile; + int const baseY = y; + int validTiles = 0; + + int enemyRange; + int searchRange; + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + enemyRange = 15; + searchRange = 7; + } else { + enemyRange = 30; + searchRange = 30; + } + + for (int index = 0; index < 9; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 0, index, &tile, &y, baseTile, baseY); + int const brushTile = tile; + if (this->OrganismLayer[brushTile] != 0) { + continue; + } + if ((this->LogicLayer[brushTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[brushTile] != 0) { + continue; + } + if ((this->LogicLayer[brushTile] & (L_WALL_OR_GATEHOUSE | L_BOULDERS | L_IRON | L_RIVER | L_FORD | L_MARSH)) + != 0) { + continue; + } + if ((this->LogicLayer[brushTile] & (L_SEA | L_PLAIN1_AND_FARM | L_ROCKY)) != 0) { + continue; + } + + int const brushY = y; + int const tileX = brushTile - DAT_ViewportRenderState::instance.translationMatrix[brushY].addXgetTile; + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT + && MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, DAT_PathFindingState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, tileX, brushY, enemyRange)) { + continue; + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + int const buildRange + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getCastleBuildRangeForMapSize, this)(); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isOpponentBuildingInRange, + DAT_PathFindingState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, tileX, brushY, + searchRange, -1, -1, buildRange + 5)) { + continue; + } + } + + if (commandBuildingType == OpenSHC::Commands::M_MAPPER_MOAT) { + if ((this->LogicLayer[brushTile] & (L_MOAT | L_MOAT_DUG_OR_PLANNED)) == 0) { + validTiles += 1; + } + } else if (commandBuildingType != OpenSHC::Commands::M_MAPPER_ANTIMOAT + || (this->LogicLayer[brushTile] & L_MOAT_DUG_OR_PLANNED) != 0) { + validTiles += 1; + } + } + if (validTiles != 0) { + return TRUE; + } + return FALSE; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeApplefarm.cpp b/src/OpenSHC/Map/TileMapState/placeApplefarm.cpp new file mode 100644 index 0000000000..e7cc666631 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeApplefarm.cpp @@ -0,0 +1,83 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic2.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_APPLE; + using OpenSHC::Map::LogicHelpers::L_NONE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00515740 + void TileMapState::placeApplefarm(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, + DAT_BuildingsState::ptr)(playerID, x, y, averageHeight, (BuildingType)buildingType, 3, playerID, variation); + this->placedBuildingID = buildingID; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::markBuildingFootprintFlag, this)(x, y, 10); + + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.AppleFarmOffsets); i++) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i] + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.AppleFarmOffsets[i].y + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.AppleFarmOffsets[i].x + x; + } + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 3); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)( + playerID, tile, this->buildingY + y, 2, L_NONE, L2_THICK_SCRUB); + index++; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.AppleFarmOffsets); i++) { + int tile = DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i]; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->LogicLayer[tile] |= L_FARM_FIELD_APPLE; + this->ChangedLayer[tile] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::placeAppleTree, DAT_LandscapeState::ptr)(buildingID, + DAT_TerrainDefinedData::instance.AppleFarmOffsets[i].x + x, + DAT_TerrainDefinedData::instance.AppleFarmOffsets[i].y + y); + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeBarracks.cpp b/src/OpenSHC/Map/TileMapState/placeBarracks.cpp new file mode 100644 index 0000000000..23e6034a7b --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeBarracks.cpp @@ -0,0 +1,168 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::MO_NONE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x005076A0 + void TileMapState::placeBarracks(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int orientation, int averageHeight) + { + uint const baseX = x; + uint const baseY = y; + int const uniqueID = DAT_GameCore::instance.uniqueGameObjectTracker; + int index = 0; + int partIndex; + if (orientation == MO_NONE) { + partIndex = 0; + } else { + partIndex = orientation / 2; + } + short placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, 15); + int buildingID = placedID; + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + x += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][0].x; + y += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][0].y; + placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_PARADEGROUND3, 5, playerID, 15); + buildingID = placedID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + int campIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + campIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->HeightLayer[tile] = averageHeight; + if (this->buildingX == 2 && this->buildingY == 2) { + this->LogicLayer[tile] |= L_BUILDING; + } + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + campIndex++; + } while (campIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + + x = DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][1].x + baseX; + y = DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][1].y + baseY; + placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_PARADEGROUND4, 5, playerID, 15); + buildingID = placedID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + campIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + campIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->HeightLayer[tile] = averageHeight; + if (this->buildingX == 2 && this->buildingY == 2) { + this->LogicLayer[tile] |= L_BUILDING; + } + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + campIndex++; + } while (campIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + + x = DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][2].x + baseX; + y = DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][2].y + baseY; + placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_PARADEGROUND2, 5, playerID, 15); + buildingID = placedID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + campIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + campIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->HeightLayer[tile] = averageHeight; + if (this->buildingX == 2 && this->buildingY == 2) { + this->LogicLayer[tile] |= L_BUILDING; + } + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + campIndex++; + } while (campIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + + if (buildingType == OpenSHC::Map::Buildings::BT_MERCENARYPOST) { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupMercenaryPostCampgroundPositions, + DAT_BuildingsState::ptr)(playerID); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupBarracksCampgroundPositions, + DAT_BuildingsState::ptr)(playerID); + } + + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeBuilding.cpp b/src/OpenSHC/Map/TileMapState/placeBuilding.cpp new file mode 100644 index 0000000000..fba4808797 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeBuilding.cpp @@ -0,0 +1,370 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.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/Map/WallAndPitchState.func.hpp" +#include "OpenSHC/UI/Helpers.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/Trees/TreeType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.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" + +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_ROCKY; + 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::Game::GameMode; + using OpenSHC::Game::GameMode2; + using OpenSHC::Game::Resources::RT_STONE; + using OpenSHC::Map::Enums::MO_NONE; + using OpenSHC::Map::LogicHelpers::MD_SEA_EDGES; + + // FUNCTION: STRONGHOLDCRUSADER 0x005162D0 + void TileMapState::placeBuilding( + int playerID, int x, int y, MappersEnum cbt, int buildingSize, int buildingOrientation) + { + MappersEnum command = (MappersEnum)(short)cbt; + if (this->skipPlacementCheck == 0) { + if (buildingOrientation == MO_NONE) { + this->DAT_TempBuildingRotation = 0; + } else { + this->DAT_TempBuildingRotation = buildingOrientation / 2; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::checkBuildingCanBePlacedHere, this)( + playerID, x, y, cbt, buildingSize); + if (this->buildingPlacementFail != FALSE) { + return; + } + } + this->skipPlacementCheck = 0; + int pitchDitchID = 0; + + BuildingType buildingType = (BuildingType)(ushort)MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(command); + short shortType = buildingType; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CRUSADER_TUTORIAL) { + if (MACRO_CALL(OpenSHC::Game_Func::Tutorial_IsActionAllowed)(2, shortType) == FALSE) { + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialHintActiveWithTimestamp)(); + return; + } + MACRO_CALL(OpenSHC::UI::Helpers_Func::SetTutorialBuildingActionState)(7, (BuildingType)shortType); + } + + int index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_SIEGE_THAT + && (this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + DAT_GameState::instance.playerDataArray[playerID].startResources[RT_STONE] += 1; + } + if ((this->LogicLayer[tile] & L_ROCKY) != 0) { + int rock = this->OrganismLayer[tile]; + if (rock >= 2000) { + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeRock, DAT_LandscapeState::ptr)( + rock - 2000); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, this->buildingX + x, this->buildingY + y); + } + } + this->LogicLayer[tile] &= ~(L_CRENEL_VARIATIONUnk | L_UNKNOWN_WALL_RELATED | L_STAIRS | L_CRENEL + | L_WALL_OR_GATEHOUSE | L_PLAIN2_AND_PITCH); + this->HeightLayer[tile] = DAT_TileMapState::instance.DefaultHeightLayer[tile]; + this->DamageLayer[tile] = 0; + if ((this->LogicLayer[tile] & L_TREE) != 0) { + int tree = this->OrganismLayer[tile]; + if (tree < 2000) { + switch (DAT_LandscapeState::instance.trees[tree].treeType) { + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_A: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_B: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_C: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_D: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_E: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_A: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_B: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_C: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_D: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_E: + case OpenSHC::Map::Trees::TT_SHRUB_PIPE_CACTUS: + case OpenSHC::Map::Trees::TT_SHRUB_SUCCULENT: + case OpenSHC::Map::Trees::TT_SHRUB_CYCAD: + case OpenSHC::Map::Trees::TT_SHRUB_PRICKLYPEAR: + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeTree, DAT_LandscapeState::ptr)(tree); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(3, x, y); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + break; + default: + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeTree, DAT_LandscapeState::ptr)(tree); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(3, x, y); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + break; + } + } + } + int unit = this->UnitLayer[tile]; + if (unit != 0) { + switch (shortType) { + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + case OpenSHC::Map::Buildings::BT_DRAWBRIDGE: + case OpenSHC::Map::Buildings::BT_CAMPFIRE: + case OpenSHC::Map::Buildings::BT_PARADEGROUND: + case OpenSHC::Map::Buildings::BT_CAMPGROUND: + case OpenSHC::Map::Buildings::BT_PARADEGROUND2: + case OpenSHC::Map::Buildings::BT_PARADEGROUND3: + case OpenSHC::Map::Buildings::BT_PARADEGROUND4: + case OpenSHC::Map::Buildings::BT_PARADEGROUND5: + case OpenSHC::Map::Buildings::BT_KILLINGPIT: + case OpenSHC::Map::Buildings::BT_PITCHDITCH: + case OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED: + 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: + break; + default: + MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::deleteUnit, DAT_UnitsState::ptr)(unit); + } + } + if ((this->LogicLayer[tile] & (L_MOAT | L_MOAT_DUG_OR_PLANNED)) != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)( + this->buildingX + x, this->buildingY + y); + this->LogicLayer[tile] &= ~(L_MOAT | L_MOAT_DUG_OR_PLANNED); + } + this->MiscDisplayLayer[tile] &= ~MD_SEA_EDGES; + index++; + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + } while (index < this->constructionTileCount); + + int highest = 0; + int lowest = 1000; + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tileHeight + = this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x]; + if (tileHeight > highest) { + highest = tileHeight; + } + if (tileHeight < lowest) { + lowest = tileHeight; + } + index++; + } while (index < this->constructionTileCount); + int averageHeight = (highest - lowest) / 2 + lowest; + + if (shortType == OpenSHC::Map::Buildings::BT_TUNNEL + && playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::playTunnelerCommandSpeech, DAT_TribesState::ptr)(); + } + + switch (shortType) { + case OpenSHC::Map::Buildings::BT_UNKNOWN1: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::stampBuildingOntoTileMap, this)(playerID, x, y, + buildingType, command - OpenSHC::Commands::M_MAPPER_UNKNOWN_248, buildingSize, buildingOrientation, + averageHeight); + break; + case OpenSHC::Map::Buildings::BT_GARDEN: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placePositiveFearfactor, this)(playerID, x, y, + buildingType, command - OpenSHC::Commands::M_MAPPER_GARDEN1, buildingSize, buildingOrientation, + averageHeight); + break; + case OpenSHC::Map::Buildings::BT_CESSPIT: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placePositiveFearfactor, this)(playerID, x, y, + buildingType, command - OpenSHC::Commands::M_MAPPER_CESS_PIT1, buildingSize, buildingOrientation, + averageHeight); + break; + case OpenSHC::Map::Buildings::BT_STATUE: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placePositiveFearfactor, this)(playerID, x, y, + buildingType, command - OpenSHC::Commands::M_MAPPER_STATUE1, buildingSize, buildingOrientation, + averageHeight); + break; + case OpenSHC::Map::Buildings::BT_SHRINE: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placePositiveFearfactor, this)(playerID, x, y, + buildingType, command - OpenSHC::Commands::M_MAPPER_SHRINE1, buildingSize, buildingOrientation, + averageHeight); + break; + case OpenSHC::Map::Buildings::BT_POND: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placePositiveFearfactor, this)(playerID, x, y, + buildingType, command - OpenSHC::Commands::M_MAPPER_POND1, buildingSize, buildingOrientation, + averageHeight); + break; + case OpenSHC::Map::Buildings::BT_STOCKPILE: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeStockpile, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_QUARRY: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeQuarry, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_WHEATFARM: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeWheatfarm, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_HOPFARM: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeHopfarm, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_DAIRYFARM: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeDairyfarm, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_APPLEFARM: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeApplefarm, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_MERCENARYPOST: + case OpenSHC::Map::Buildings::BT_BARRACKS: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBarracks, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_ENGINEERSGUILD: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeEngineersguild, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_TUNNELERSGUILD: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeTunnelersguild, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_OILSMELTER: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeOilsmelter, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_MANORHOUSE: + case OpenSHC::Map::Buildings::BT_STONEKEEP: + case OpenSHC::Map::Buildings::BT_STRONGHOLD: + case OpenSHC::Map::Buildings::BT_KEEPFOUR: + case OpenSHC::Map::Buildings::BT_KEEPFIVE: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeKeep, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + 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: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeTower, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeGatehouseLarge, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeGatehouseSmall, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_DRAWBRIDGE: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeDrawbridge, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_FIREBALLISTA: + case OpenSHC::Map::Buildings::BT_CATAPULT: + case OpenSHC::Map::Buildings::BT_TREBUCHET: + case OpenSHC::Map::Buildings::BT_BATTERINGRAM: + case OpenSHC::Map::Buildings::BT_SIEGETOWER: + case OpenSHC::Map::Buildings::BT_SHIELD: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeSiegeTent, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_KILLINGPIT: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeKillingPit, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_PITCHDITCH: + pitchDitchID = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placePitchDitch, this)(playerID, x, y); + break; + case OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeSiegetowerPlaced, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + default: + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeWorkshopOrHovel, this)( + playerID, x, y, buildingType, buildingSize, buildingOrientation, averageHeight); + break; + case OpenSHC::Map::Buildings::BT_WOODGATE1: + break; + } + + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + if (shortType != OpenSHC::Map::Buildings::BT_PITCHDITCH) { + MACRO_CALL_MEMBER(OpenSHC::Map::WallAndPitchState_Func::startBuildingDestructionConfirmation, + DAT_WallAndPitchState::ptr)(this->placedBuildingID); + } else if (pitchDitchID != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::WallAndPitchState_Func::placePitchDitch, DAT_WallAndPitchState::ptr)( + pitchDitchID); + } + } + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processPlacementResourceLossForBuildingType, + DAT_BuildingsState::ptr)(playerID, (BuildingType)shortType, 0); + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::hasLessWoodThanTheCostOfAWoodcuttersHutAndNoWoodcutters, + DAT_BuildingsState::ptr)(playerID, shortType) + != 0) { + DAT_BuildingsState::instance.buildings[this->placedBuildingID].suppressDestroyRefund = 1; + } + MACRO_CALL_MEMBER(OpenSHC::UI::MinimapViewState_Func::triggerMinimapRedraw, DAT_MinimapViewState::ptr)(1); + int radius; + if (buildingSize <= 5) { + radius = 9; + } else { + radius = buildingSize + 5; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(radius, x, y); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + if (DAT_GameSynchronyState::instance.currentGameMode == OpenSHC::Game::GM_SOLITARY) { + this->forceUpdateMacroLayerFlag = 1; + this->field_0x55487c = 200; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeDairyfarm.cpp b/src/OpenSHC/Map/TileMapState/placeDairyfarm.cpp new file mode 100644 index 0000000000..c93674ceb2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeDairyfarm.cpp @@ -0,0 +1,102 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic2.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_DAIRY; + using OpenSHC::Map::LogicHelpers::L_NONE; + + // FUNCTION: STRONGHOLDCRUSADER 0x005154D0 + void TileMapState::placeDairyfarm(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, + DAT_BuildingsState::ptr)(playerID, x, y, averageHeight, (BuildingType)buildingType, 3, playerID, variation); + this->placedBuildingID = buildingID; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::markBuildingFootprintFlag, this)(x, y, 10); + + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.field_0xf5c[0]); i++) { + int& tileRef = DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i]; + tileRef = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .field_0xf5c[DAT_GameState::instance.playerDataArray[playerID] + .dairyFarmVariationMod4][i] + .offset.y + + y] + .addXgetTile + + DAT_TerrainDefinedData::instance + .field_0xf5c[DAT_GameState::instance.playerDataArray[playerID].dairyFarmVariationMod4][i] + .offset.x + + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tileRef); + if (i >= 4) { + this->DamageLayer[tileRef] + = DAT_TerrainDefinedData::instance + .field_0xf5c[DAT_GameState::instance.playerDataArray[playerID].dairyFarmVariationMod4][i] + .property; + } + } + DAT_GameState::instance.playerDataArray[playerID].dairyFarmVariationMod4++; + if (DAT_GameState::instance.playerDataArray[playerID].dairyFarmVariationMod4 > 3) { + DAT_GameState::instance.playerDataArray[playerID].dairyFarmVariationMod4 = 0; + } + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 3); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)( + playerID, tile, this->buildingY + y, 2, L_NONE, L2_THICK_SCRUB); + index++; + } while (index < this->constructionTileCount); + + for (int i = 4; i < countof(DAT_TerrainDefinedData::instance.field_0xf5c[0]); i++) { + int tile = DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i]; + this->LogicLayer[tile] |= L_FARM_FIELD_DAIRY; + this->BuildingLayer[tile] = buildingID; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)( + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[tile], tile); + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeDrawbridge.cpp b/src/OpenSHC/Map/TileMapState/placeDrawbridge.cpp new file mode 100644 index 0000000000..089e77bec5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeDrawbridge.cpp @@ -0,0 +1,55 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_MOAT; + + // FUNCTION: STRONGHOLDCRUSADER 0x00514DE0 + void TileMapState::placeDrawbridge(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int orientation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, orientation); + int const orientationIndex = orientation / 2; + this->placedBuildingID = buildingID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + if (DAT_TerrainDefinedData::instance.DrawbridgeTileMoatProperty[index] != 0) { + this->LogicLayer[tile] |= L_BUILDING; + } + if (DAT_TerrainDefinedData::instance.DrawbridgeOrientationMapping[orientationIndex][index] != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::createMoatData, this)( + playerID, this->buildingX + x, this->buildingY + y, TRUE); + this->LogicLayer[tile] &= ~L_MOAT; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMoatVisualStateAtTile, this)(tile, 0); + this->HeightLayer[tile] = 0; + } else { + this->LogicLayer[tile] &= ~L_MOAT; + } + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeEngineersguild.cpp b/src/OpenSHC/Map/TileMapState/placeEngineersguild.cpp new file mode 100644 index 0000000000..6f1ff17193 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeEngineersguild.cpp @@ -0,0 +1,84 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::MO_NONE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507BD0 + void TileMapState::placeEngineersguild(int playerID, uint x, uint y, BuildingTypeShort buildingType, + uint buildingSize, int orientation, int averageHeight) + { + int const uniqueID = DAT_GameCore::instance.uniqueGameObjectTracker; + int index = 0; + int partIndex; + if (orientation == MO_NONE) { + partIndex = 0; + } else { + partIndex = orientation / 2; + } + short placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, 15); + int buildingID = placedID; + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + x += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][1].x; + y += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][1].y; + placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_PARADEGROUND, 5, playerID, 15); + buildingID = placedID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + int campIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + campIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->HeightLayer[tile] = averageHeight; + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + campIndex++; + } while (campIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupEngineersGuildParagroundPositions, + DAT_BuildingsState::ptr)(playerID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeGatehouseLarge.cpp b/src/OpenSHC/Map/TileMapState/placeGatehouseLarge.cpp new file mode 100644 index 0000000000..08e23db419 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeGatehouseLarge.cpp @@ -0,0 +1,61 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_GATEHOUSE_RAISED; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507560 + void TileMapState::placeGatehouseLarge(int playerID, uint x, uint y, BuildingTypeShort buildingType, + uint buildingSize, int variation, int averageHeight) + { + int uniqueID = DAT_GameCore::instance.uniqueGameObjectTracker; + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight + 90; + this->LogicLayer[tile] |= L_WALL_OR_GATEHOUSE; + this->WallOwnerLayer[tile] = this->WallOwnerLayer[tile] & ~WO_OWNER_MASK | (playerID - 1); + this->MiscDisplayLayer[tile] |= MD_GATEHOUSE_RAISED; + this->BuildingLayer[tile] = buildingID; + index++; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + + if (variation == 80) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::createClimbData, + DAT_PathFindingState::ptr)(3, buildingID, 0, 2, 0); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::createClimbData, + DAT_PathFindingState::ptr)(3, buildingID, 0, 0, 0); + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeGatehouseSmall.cpp b/src/OpenSHC/Map/TileMapState/placeGatehouseSmall.cpp new file mode 100644 index 0000000000..a19a90687d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeGatehouseSmall.cpp @@ -0,0 +1,61 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_GATEHOUSE_RAISED; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507420 + void TileMapState::placeGatehouseSmall(int playerID, uint x, uint y, BuildingTypeShort buildingType, + uint buildingSize, int variation, int averageHeight) + { + int uniqueID = DAT_GameCore::instance.uniqueGameObjectTracker; + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight + 90; + this->LogicLayer[tile] |= L_WALL_OR_GATEHOUSE; + this->WallOwnerLayer[tile] = this->WallOwnerLayer[tile] & ~WO_OWNER_MASK | (playerID - 1); + this->MiscDisplayLayer[tile] |= MD_GATEHOUSE_RAISED; + this->BuildingLayer[tile] = buildingID; + index++; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + + if (variation == 80) { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::createClimbData, + DAT_PathFindingState::ptr)(4, buildingID, 0, 2, 0); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::createClimbData, + DAT_PathFindingState::ptr)(4, buildingID, 0, 0, 0); + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeHopfarm.cpp b/src/OpenSHC/Map/TileMapState/placeHopfarm.cpp new file mode 100644 index 0000000000..da023d0baf --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeHopfarm.cpp @@ -0,0 +1,96 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic2.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.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 0x005151C0 + void TileMapState::placeHopfarm(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int index = 0; + int const buildingID = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, + DAT_BuildingsState::ptr)(playerID, x, y, averageHeight, (BuildingType)buildingType, 3, playerID, variation); + this->placedBuildingID = buildingID; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::markBuildingFootprintFlag, this)(x, y, 9); + int const layout = DAT_GameState::instance.playerDataArray[playerID].unkHopFarmVariation; + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.HopFarmProperty1[0]); i++) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i] + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.HopFarmProperty1[layout][i].y + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.HopFarmProperty1[layout][i].x + x; + } + DAT_BuildingsState::instance.buildings[buildingID].someFarmRelatedState = layout != 0 ? 7 : 81; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 3); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= OpenSHC::Map::LogicHelpers::L_BUILDING; + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)(playerID, tile, this->buildingY + y, 2, + OpenSHC::Map::LogicHelpers::L_NONE, OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB); + index++; + } while (index < this->constructionTileCount); + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.HopFarmProperty1[0]); i++) { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .HopFarmProperty1[DAT_GameState::instance.playerDataArray[playerID] + .unkHopFarmVariation][i] + .y + + y] + .addXgetTile + + DAT_TerrainDefinedData::instance + .HopFarmProperty1[DAT_GameState::instance.playerDataArray[playerID].unkHopFarmVariation][i] + .x + + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->LogicLayer[tile] |= OpenSHC::Map::LogicHelpers::L_FARM_FIELD_HOP; + this->BuildingLayer[tile] = buildingID; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)( + DAT_TerrainDefinedData::instance + .HopFarmProperty1[DAT_GameState::instance.playerDataArray[playerID].unkHopFarmVariation][i] + .y + + y, + tile); + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + DAT_GameState::instance.playerDataArray[playerID].unkHopFarmVariation += 1; + if (DAT_GameState::instance.playerDataArray[playerID].unkHopFarmVariation > 1) { + DAT_GameState::instance.playerDataArray[playerID].unkHopFarmVariation = 0; + } + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeKeep.cpp b/src/OpenSHC/Map/TileMapState/placeKeep.cpp new file mode 100644 index 0000000000..e00ea9fd93 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeKeep.cpp @@ -0,0 +1,287 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Game/Player/PlayerDataBuildingCategoryEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic2.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::MO_NONE; + using OpenSHC::Map::Enums::MO_NORTH; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::MD_BUILDING_MAIN_TILE; + + using OpenSHC::Game::Player::PlayerDataBuildingCategoryEnum; + + // FUNCTION: STRONGHOLDCRUSADER 0x005146D0 + void TileMapState::placeKeep( + int playerID, uint x, uint y, BuildingType buildingType, uint buildingSize, int orientation, int averageHeight) + { + if (this->clearKeepFootprintOnPlace != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::demolishBuildingsInKeepsConstructionFootprint, this)( + playerID, x, y, buildingType, buildingSize, orientation, averageHeight); + this->clearKeepFootprintOnPlace = 0; + } + + int keepKind = 0; + int index = 0; + int const uid = DAT_GameCore::instance.uniqueGameObjectTracker; + int const keepOrientation = orientation; + int const grassy = this->Logic2Layer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x] + & (OpenSHC::Map::LogicHelpers::L2_OASIS_GRASS | OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB); + short const keepType = buildingType; + uint const baseX = x; + uint const baseY = y; + int buildingID = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, + DAT_BuildingsState::ptr)(playerID, x, y, averageHeight, (BuildingType)keepType, buildingSize, playerID, 15); + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uid; + DAT_BuildingsState::instance.buildings[buildingID].orientation = orientation; + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::computeBuildingCategoryEntryPointAndDestroyEarlierBuilding, + DAT_GameState::ptr)(buildingID, playerID, OpenSHC::Game::Player::PDBCE_KEEP); + if (orientation == MO_NONE) { + orientation = MO_NORTH; + } + + int tile; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + if (keepType == OpenSHC::Map::Buildings::BT_MANORHOUSE) { + this->LogicLayer[tile] |= L_BUILDING; + } else { + this->LogicLayer[tile] |= L_KEEP_NON_MANOR_HOUSE; + } + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = (uchar)keepType; + if (grassy != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)(playerID, tile, + this->buildingY + y, 3, OpenSHC::Map::LogicHelpers::L_NONE, + OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)(playerID, tile, + this->buildingY + y, 6, OpenSHC::Map::LogicHelpers::L_NONE, + OpenSHC::Map::LogicHelpers::L2_EARTH_AND_STONES); + } + this->ChangedLayer[tile] = 2; + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + if (keepType == OpenSHC::Map::Buildings::BT_MANORHOUSE || keepType == OpenSHC::Map::Buildings::BT_STONEKEEP) { + keepKind = 2; + } + tile = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE] + [orientation / 2][0] + .y + + y] + .addXgetTile + + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][0] + .x + + x; + buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)(playerID, + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][0] + .x + + x, + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][0] + .y + + y, + averageHeight, OpenSHC::Map::Buildings::BT_KEEPDOOR_LEFT, 1, playerID, 15); + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uid; + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated = keepKind; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + DAT_BuildingsState::instance.buildings[buildingID].orientation = keepOrientation; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + this->ChangedLayer[tile] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].y, tile); + + tile = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE] + [orientation / 2][1] + .y + + y] + .addXgetTile + + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][1] + .x + + x; + buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)(playerID, + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][1] + .x + + x, + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][1] + .y + + y, + averageHeight, OpenSHC::Map::Buildings::BT_KEEPDOOR, 1, playerID, 15); + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uid; + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated = keepKind / 2; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + DAT_BuildingsState::instance.buildings[buildingID].orientation = keepOrientation; + this->MiscDisplayLayer[tile] |= MD_BUILDING_MAIN_TILE; + this->BuildingLayer[tile] = buildingID; + this->ChangedLayer[tile] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].y, tile); + + tile = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE] + [orientation / 2][2] + .y + + y] + .addXgetTile + + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][2] + .x + + x; + buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)(playerID, + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][2] + .x + + x, + DAT_TerrainDefinedData::instance + .keepDoorOffsets[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2][2] + .y + + y, + averageHeight, OpenSHC::Map::Buildings::BT_KEEPDOOR_RIGHT, 1, playerID, 15); + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uid; + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated = keepKind; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + DAT_BuildingsState::instance.buildings[buildingID].orientation = keepOrientation; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + this->ChangedLayer[tile] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].y, tile); + + y += DAT_TerrainDefinedData::instance + .keepOutbuildingOffsets_0x384[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2] + .yOffset; + x += DAT_TerrainDefinedData::instance + .keepOutbuildingOffsets_0x384[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2] + .xOffset; + buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_CAMPGROUND, 7, playerID, 15); + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uid; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + DAT_BuildingsState::instance.buildings[buildingID].orientation = keepOrientation; + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::computeBuildingCategoryEntryPointAndDestroyEarlierBuilding, + DAT_GameState::ptr)(buildingID, playerID, OpenSHC::Game::Player::PDBCE_CAMPGROUND); + + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 7); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)( + DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + + x); + index++; + } while (index < this->constructionTileCount); + + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_TerrainDefinedData::instance.field_0x444)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_BuildingsState::instance.buildings[buildingID].y + + DAT_TerrainDefinedData::instance.field_0x444[index].y] + .addXgetTile + + DAT_BuildingsState::instance.buildings[buildingID].x + + DAT_TerrainDefinedData::instance.field_0x444[index].x; + } + this->HeightLayer[tile] = averageHeight; + if (this->buildingX == 3 && this->buildingY == 3) { + this->LogicLayer[tile] |= L_BUILDING; + } + if (this->buildingX == 3 && this->buildingY == 2) { + this->LogicLayer[tile] |= L_BUILDING; + } + if (this->buildingX == 3 && this->buildingY == 4) { + this->LogicLayer[tile] |= L_BUILDING; + } + if (this->buildingX == 2 && this->buildingY == 3) { + this->LogicLayer[tile] |= L_BUILDING; + } + if (this->buildingX == 4 && this->buildingY == 3) { + this->LogicLayer[tile] |= L_BUILDING; + } + this->BuildingLayer[tile] = buildingID; + this->ChangedLayer[tile] = 2; + if (grassy != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)(playerID, tile, + this->buildingY + y, 3, OpenSHC::Map::LogicHelpers::L_NONE, + OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)(playerID, tile, + this->buildingY + y, 6, OpenSHC::Map::LogicHelpers::L_NONE, + OpenSHC::Map::LogicHelpers::L2_EARTH_AND_STONES); + } + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(10, x, y); + + x = DAT_TerrainDefinedData::instance + .keepOutbuildingOffsets_0x3e4[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2] + .xOffset + + baseX; + y = DAT_TerrainDefinedData::instance + .keepOutbuildingOffsets_0x3e4[keepType - OpenSHC::Map::Buildings::BT_MANORHOUSE][orientation / 2] + .yOffset + + baseY; + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 5); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)( + DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + this->buildingX + + x); + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeStockpile, this)( + playerID, x, y, OpenSHC::Map::Buildings::BT_STOCKPILE, 5, 15, averageHeight); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeKillingPit.cpp b/src/OpenSHC/Map/TileMapState/placeKillingPit.cpp new file mode 100644 index 0000000000..d587a897ae --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeKillingPit.cpp @@ -0,0 +1,78 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic2.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x00514520 + void TileMapState::placeKillingPit(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + /* the original masks the terrain bits once, before the building is even created */ + int grassOrScrub = this->Logic2Layer[DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x] + & (OpenSHC::Map::LogicHelpers::L2_OASIS_GRASS | OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB); + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + if (buildingType != OpenSHC::Map::Buildings::BT_KILLINGPIT) { + averageHeight -= 4; + if (averageHeight < 0) { + averageHeight = 0; + } + } + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = (uchar)buildingType; + if (buildingType != OpenSHC::Map::Buildings::BT_KILLINGPIT) { + /* bug:fixme: a pit dug in grass comes back as thick scrub, not as the terrain it replaced */ + if (grassOrScrub != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)(playerID, tile, + this->buildingY + y, 3, OpenSHC::Map::LogicHelpers::L_NONE, + OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)(playerID, tile, + this->buildingY + y, 3, OpenSHC::Map::LogicHelpers::L_NONE, + OpenSHC::Map::LogicHelpers::L2_EARTH_AND_STONES); + } + } + index++; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeOilsmelter.cpp b/src/OpenSHC/Map/TileMapState/placeOilsmelter.cpp new file mode 100644 index 0000000000..1afc491507 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeOilsmelter.cpp @@ -0,0 +1,85 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::MO_NONE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508030 + void TileMapState::placeOilsmelter(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int orientation, int averageHeight) + { + int const uniqueID = DAT_GameCore::instance.uniqueGameObjectTracker; + int index = 0; + int partIndex; + if (orientation == MO_NONE) { + partIndex = 0; + } else { + partIndex = orientation / 2; + } + short tileBuildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, 15); + int buildingID = tileBuildingID; + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = tileBuildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + index++; + } while (index < this->constructionTileCount); + int const smelterID = buildingID; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + x += DAT_TerrainDefinedData::instance.field_0x19c[partIndex].x; + y += DAT_TerrainDefinedData::instance.field_0x19c[partIndex].y; + tileBuildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_CAMPFIRE, 4, playerID, 15); + buildingID = tileBuildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + DAT_BuildingsState::instance.buildings[smelterID].quarryStockpileID = tileBuildingID; + int campIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + campIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->HeightLayer[tile] = averageHeight; + this->BuildingLayer[tile] = tileBuildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + campIndex++; + } while (campIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setTileRefsForOilSmelter, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placePitchDitch.cpp b/src/OpenSHC/Map/TileMapState/placePitchDitch.cpp new file mode 100644 index 0000000000..32f282bff1 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placePitchDitch.cpp @@ -0,0 +1,69 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/SEC_RNG.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_EDGEUnk; + using OpenSHC::Map::LogicHelpers::MD_RUBBLE_INNERUnk; + + // FUNCTION: STRONGHOLDCRUSADER 0x005116E0 + int TileMapState::placePitchDitch(int playerID, int x, int y) + { + if (x < 0 || x > MC_MAP_XY_LIMIT_INCLUSIVE || y < 0 || y > MC_MAP_XY_LIMIT_INCLUSIVE) { + return 0; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { + return 0; + } + + int const existingPitchDitchID = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getPitchDitchIDForTile, + this)(DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x); + if (existingPitchDitchID != 0) { + return existingPitchDitchID; + } + + for (int pitchDitchID = 1; pitchDitchID < countof(this->pitchDitches); pitchDitchID++) { + if (this->pitchDitches[pitchDitchID].owner != 0) { + continue; + } + + if (pitchDitchID >= this->maxPitchDitchCount) { + this->maxPitchDitchCount = pitchDitchID + 1; + } + this->pitchDitches[pitchDitchID].owner = playerID; + this->pitchDitches[pitchDitchID].uid = DAT_GameCore::instance.uniqueGameObjectTracker; + DAT_GameCore::instance.uniqueGameObjectTracker++; + this->pitchDitches[pitchDitchID].y = y; + this->pitchDitches[pitchDitchID].x = x; + this->pitchDitches[pitchDitchID].tile + = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + this->pitchDitches[pitchDitchID].state = 0; + this->pitchDitches[pitchDitchID].burnTimer = 0; + this->pitchDitches[pitchDitchID].rng = SEC_RNG::instance.currentNumber2; + PitchDitch const& pitchDitch = this->pitchDitches[pitchDitchID]; + if (this->HeightLayer[pitchDitch.tile] > 4) { + this->HeightLayer[pitchDitch.tile] -= 4; + } else { + this->HeightLayer[pitchDitch.tile] = 0; + } + MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)(); + this->LogicLayer[pitchDitch.tile] |= L_PLAIN2_AND_PITCH; + this->MiscDisplayLayer[pitchDitch.tile] &= ~MD_RUBBLE_INNERUnk; + this->MiscDisplayLayer[pitchDitch.tile] &= ~MD_RUBBLE_EDGEUnk; + this->ChangedLayer[pitchDitch.tile] = 2; + return pitchDitchID; + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placePositiveFearfactor.cpp b/src/OpenSHC/Map/TileMapState/placePositiveFearfactor.cpp new file mode 100644 index 0000000000..d87e231f18 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placePositiveFearfactor.cpp @@ -0,0 +1,55 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00506F40 + void TileMapState::placePositiveFearfactor(int playerID, uint x, uint y, BuildingTypeShort buildingType, + short variation, uint buildingSize, int orientation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + index++; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeQuarry.cpp b/src/OpenSHC/Map/TileMapState/placeQuarry.cpp new file mode 100644 index 0000000000..b213ca68fb --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeQuarry.cpp @@ -0,0 +1,117 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/AI/AIVState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_AIVState.hpp" +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508250 + void TileMapState::placeQuarry(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int index = 0; + int uid = DAT_GameCore::instance.uniqueGameObjectTracker; + int quarryID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = quarryID; + DAT_BuildingsState::instance.buildings[quarryID].uidWhenPlaced = uid; + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + index++; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = quarryID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(quarryID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(quarryID); + + for (int attempt = 1; attempt < 10; attempt++) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::findQuarryPileLocation, DAT_BuildingsState::ptr)( + playerID, x, y, buildingSize, 2, attempt, OpenSHC::Commands::M_MAPPER_QUARRYPILE); + if (this->buildingPlacementFail == FALSE) { + break; + } + } + if (this->buildingPlacementFail != FALSE) { + return; + } + + x += DAT_BuildingsState::instance.DAT_TempXOffset; + y += DAT_BuildingsState::instance.DAT_TempYOffset; + int tileIndex = 0; + int lowest = 1000; + int highest = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 2); + int tileHeight + = this->HeightLayer[DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + x + this->buildingX]; + if (tileHeight > highest) { + highest = tileHeight; + } + if (tileHeight < lowest) { + lowest = tileHeight; + } + tileIndex++; + } while (tileIndex < this->constructionTileCount); + averageHeight = (highest - lowest) / 2 + lowest; + + tileIndex = 0; + int pileID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_QUARRYSTOCKPILE, 2, playerID, variation); + MACRO_CALL_MEMBER(OpenSHC::AI::AIVState_Func::incrementStructureHeatMapTile, DAT_AIVState::ptr)(x, y); + DAT_BuildingsState::instance.buildings[pileID].uidWhenPlaced = uid; + DAT_BuildingsState::instance.buildings[quarryID].quarryStockpileID = pileID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(tileIndex, 2); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = pileID; + tileIndex++; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (tileIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(pileID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(pileID); + + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[pileID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeRock.cpp b/src/OpenSHC/Map/TileMapState/placeRock.cpp new file mode 100644 index 0000000000..b453125f5a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeRock.cpp @@ -0,0 +1,138 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.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_MARSH; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_OIL; + using OpenSHC::Map::LogicHelpers::L_PEBBLES; + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_UNNAMED_0x40; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB4D0 + void TileMapState::placeRock(uint x, uint y, int kind) + { + int size = 1; + int rockType = 0; + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { + return; + } + short const rockKind = *(short volatile*)&kind; + if (rockKind == 0) { + rockType = 1; + } else if (rockKind == 1) { + rockType = 2; + } else if (rockKind == 2) { + rockType = 3; + } else if (rockKind == 3) { + rockType = 4; + } else if (rockKind == 4) { + size = 2; + rockType = 5; + } else if (rockKind == 5) { + size = 2; + rockType = 6; + } else if (rockKind == 6) { + size = 2; + rockType = 7; + } else if (rockKind == 7) { + size = 2; + rockType = 8; + } else if (rockKind == 8) { + size = 3; + rockType = 9; + } else if (rockKind == 9) { + size = 3; + rockType = 10; + } else if (rockKind == 10) { + size = 3; + rockType = 11; + } else if (rockKind == 11) { + size = 3; + rockType = 12; + } else if (rockKind == 12) { + rockType = 13; + size = 4; + } else if (rockKind == 13) { + rockType = 14; + size = 4; + } else if (rockKind == 14) { + rockType = 15; + size = 4; + } else if (rockKind == 15) { + rockType = 16; + size = 4; + } + + kind = 1000; + int highest = 0; + int index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, size); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + return; + } + if ((this->LogicLayer[tile] & L_BUILDING) != 0) { + return; + } + if (this->OrganismLayer[tile] != 0) { + return; + } + if (this->HeightLayer[tile] > highest) { + highest = this->HeightLayer[tile]; + } + if (this->HeightLayer[tile] < kind) { + kind = this->HeightLayer[tile]; + } + index++; + } while (index < this->constructionTileCount); + + int const height = (highest - *(int volatile*)&kind) / 2 + kind; + int const rockID = MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::createRock, DAT_LandscapeState::ptr)( + x, y, rockType, size, this->rockOrientation); + kind = rockID + 2000; + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, size); + index++; + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->HeightLayer[tile] = height; + this->DefaultHeightLayer[tile] = height; + this->LogicLayer[tile] &= ~(L_SEA | L_PLAIN2_AND_PITCH | L_UNNAMED_0x40 | L_BOULDERS | L_PEBBLES | L_IRON + | L_RIVER | L_FORD | L_MARSH | L_MOAT | L_OIL); + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= L_ROCKY; + this->OrganismLayer[tile] = kind; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(9, x, y); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + this->forceUpdateMacroLayerFlag = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeSiegeTent.cpp b/src/OpenSHC/Map/TileMapState/placeSiegeTent.cpp new file mode 100644 index 0000000000..727bf75cb0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeSiegeTent.cpp @@ -0,0 +1,56 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00506E10 + void TileMapState::placeSiegeTent(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + index++; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeSiegetowerPlaced.cpp b/src/OpenSHC/Map/TileMapState/placeSiegetowerPlaced.cpp new file mode 100644 index 0000000000..296ebd2a1a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeSiegetowerPlaced.cpp @@ -0,0 +1,42 @@ +#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 { + + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00506D40 + void TileMapState::placeSiegetowerPlaced(int playerID, uint x, uint y, BuildingTypeShort buildingType, + uint buildingSize, int variation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_KEEP_NON_MANOR_HOUSE; + this->BuildingLayer[tile] = buildingID; + index++; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeStockpile.cpp b/src/OpenSHC/Map/TileMapState/placeStockpile.cpp new file mode 100644 index 0000000000..135993b937 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeStockpile.cpp @@ -0,0 +1,86 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508540 + void TileMapState::placeStockpile(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int const uid = DAT_GameCore::instance.uniqueGameObjectTracker; + + int buildingID; + for (int part = 0; part < countof(DAT_TerrainDefinedData::instance.Stockpile_BuildingPartsOffsets); part++) { + buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)(playerID, + DAT_TerrainDefinedData::instance.Stockpile_BuildingPartsOffsets[part].x + x, + DAT_TerrainDefinedData::instance.Stockpile_BuildingPartsOffsets[part].y + y, averageHeight + 10, + (BuildingType)buildingType, 2, playerID, variation); + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uid; + DAT_BuildingsState::instance.buildings[buildingID].field_0x190 = part + 1; + int index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 2); + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.Stockpile_BuildingPartsOffsets[part].y + + this->buildingY + y] + .addXgetTile + + DAT_TerrainDefinedData::instance.Stockpile_BuildingPartsOffsets[part].x + x + this->buildingX; + this->HeightLayer[tile] = averageHeight + 10; + this->LogicLayer[tile] |= L_STOCKPILEUnk | L_WALL_OR_GATEHOUSE | L_BUILDING; + this->WallOwnerLayer[tile] = this->WallOwnerLayer[tile] & ~WO_OWNER_MASK | (playerID - 1); + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + + this->placedBuildingID = buildingID; + for (int slot = 0; slot != countof(DAT_TerrainDefinedData::instance.StockpilePathableOffsets); slot++) { + Navigation::Algorithms::XYPair const& offset + = DAT_TerrainDefinedData::instance.StockpilePathableOffsets[slot]; + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[offset.y + y].addXgetTile + offset.x + x; + this->LogicLayer[tile] |= L_STOCKPILEUnk | L_WALL_OR_GATEHOUSE; + this->HeightLayer[tile] = averageHeight + 10; + this->AlphaGFXLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + this->WallOwnerLayer[tile] &= ~WO_OWNER_MASK; + this->WallOwnerLayer[tile] |= playerID - 1; + this->ChangedLayer[tile] = 2; + } + + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeTower.cpp b/src/OpenSHC/Map/TileMapState/placeTower.cpp new file mode 100644 index 0000000000..1741a06357 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeTower.cpp @@ -0,0 +1,57 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.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; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507130 + void TileMapState::placeTower(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int uniqueID = DAT_GameCore::instance.uniqueGameObjectTracker; + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + if (DAT_TerrainDefinedData::instance.TowerTileOffsetsBySize[buildingSize][0] == index) { + this->LogicLayer[tile] |= L_BUILDING; + } else if (DAT_TerrainDefinedData::instance.TowerTileOffsetsBySize[buildingSize][1] == index) { + this->LogicLayer[tile] |= L_BUILDING; + } else if (DAT_TerrainDefinedData::instance.TowerTileOffsetsBySize[buildingSize][2] == index) { + this->LogicLayer[tile] |= L_BUILDING; + } else if (DAT_TerrainDefinedData::instance.TowerTileOffsetsBySize[buildingSize][3] == index) { + this->LogicLayer[tile] |= L_BUILDING; + } else { + this->LogicLayer[tile] |= L_KEEP_NON_MANOR_HOUSE; + } + this->BuildingLayer[tile] = buildingID; + index++; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeTree.cpp b/src/OpenSHC/Map/TileMapState/placeTree.cpp new file mode 100644 index 0000000000..0adb4a70b6 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeTree.cpp @@ -0,0 +1,92 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.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_PEBBLES; + 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_TREE; + using OpenSHC::Map::LogicHelpers::L_TREE_VARIATION; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00515DA0 + void TileMapState::placeTree(uint x, uint y, MappersEnumShort treeType) + { + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { + return; + } + + int const stage = MACRO_CALL_MEMBER( + OpenSHC::Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage, DAT_LandscapeState::ptr)( + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::mapUITreeTypeToLogicalTreeType, + DAT_LandscapeState::ptr)((OpenSHC::Commands::MappersEnum)treeType), + 3); + int const baseTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[stage]; + if ((this->LogicLayer[tile] + & (L_SEA | L_PLAIN1_AND_FARM | L_BORDER | L_BORDER_EDGE | L_ROCKY | L_WALL_OR_GATEHOUSE | L_BUILDING + | L_TREE_VARIATION | L_BOULDERS | L_PEBBLES | L_IRON | L_RIVER | L_FORD | L_KEEP_NON_MANOR_HOUSE + | L_MARSH | L_MOAT)) + != 0) { + return; + } + + int brushY = y; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &brushY, baseTile, y); + if ((this->LogicLayer[tile] & L_BORDER) != 0) { + break; + } + if ((this->LogicLayer[tile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_RIVER | L_KEEP_NON_MANOR_HOUSE)) != 0) { + return; + } + if ((this->LogicLayer[tile] & L_ROCKY) != 0) { + return; + } + if (this->OrganismLayer[tile] != 0) { + return; + } + } + + short logicalType = MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::mapUITreeTypeToLogicalTreeType, + DAT_LandscapeState::ptr)((OpenSHC::Commands::MappersEnum)treeType); + int const treeID = MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::createTree, DAT_LandscapeState::ptr)( + x, y, (TreeType)logicalType, stage, 0, 0, 3); + this->LogicLayer[DAT_LandscapeState::instance.trees[treeID].tile] &= ~L_ROCKY; + this->LogicLayer[DAT_LandscapeState::instance.trees[treeID].tile] |= L_TREE; + this->OrganismLayer[DAT_LandscapeState::instance.trees[treeID].tile] = treeID; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::applyTreeBrushToLogicalLayer, this)(treeID, 0); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)( + DAT_LandscapeState::instance.trees[treeID].yPosition, DAT_LandscapeState::instance.trees[treeID].tile); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeTunnelersguild.cpp b/src/OpenSHC/Map/TileMapState/placeTunnelersguild.cpp new file mode 100644 index 0000000000..b04ddcf574 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeTunnelersguild.cpp @@ -0,0 +1,84 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::MO_NONE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507E00 + void TileMapState::placeTunnelersguild(int playerID, uint x, uint y, BuildingTypeShort buildingType, + uint buildingSize, int orientation, int averageHeight) + { + int const uniqueID = DAT_GameCore::instance.uniqueGameObjectTracker; + int index = 0; + int partIndex; + if (orientation == MO_NONE) { + partIndex = 0; + } else { + partIndex = orientation / 2; + } + short placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, 15); + int buildingID = placedID; + this->placedBuildingID = buildingID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + index++; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + x += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][1].x; + y += DAT_TerrainDefinedData::instance.BuildingPartsOffsets[partIndex][1].y; + placedID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, OpenSHC::Map::Buildings::BT_PARADEGROUND5, 5, playerID, 15); + buildingID = placedID; + DAT_BuildingsState::instance.buildings[buildingID].uidWhenPlaced = uniqueID; + DAT_BuildingsState::instance.buildings[buildingID].quarryStockpileID = this->placedBuildingID; + int campIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + campIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->HeightLayer[tile] = averageHeight; + this->BuildingLayer[tile] = placedID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + campIndex++; + } while (campIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupTunnelersGuildCampgroundPositions, + DAT_BuildingsState::ptr)(playerID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeWalls.cpp b/src/OpenSHC/Map/TileMapState/placeWalls.cpp new file mode 100644 index 0000000000..3a135097e5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeWalls.cpp @@ -0,0 +1,270 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/WallAndPitchState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Map/Walls/WallConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_MinimapViewState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WallAndPitchState.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::WO_OWNER_MASK; + using OpenSHC::Map::Units::UnitType; + using OpenSHC::Map::Units::States::UnitState; + using OpenSHC::Map::Walls::WALL_HIGH_CRENAL_HEIGHT; + using OpenSHC::Map::Walls::WALL_HIGH_HEIGHT; + using OpenSHC::Map::Walls::WALL_LOW_CRENAL_HEIGHT; + using OpenSHC::Map::Walls::WALL_LOW_HEIGHT; + + // FUNCTION: STRONGHOLDCRUSADER 0x00502F30 + void TileMapState::placeWalls( + int playerID, int x1, int y1, int x2, int y2, MappersEnumShort wallType, int tileCountUnk) + { + int budget = 0; + int wallCount = 0; + int placed = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateWallBuildPath, this)( + playerID, x1, y1, x2, y2, wallType); + if (this->illegalBuild != FALSE) { + return; + } + + this->constructionTileCount = MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::getWallTilesThatCanBeBuilt, DAT_GameState::ptr)(playerID, 4); + int overshoot = 2; + if (wallType == OpenSHC::Commands::M_MAPPER_STAIR) { + budget = this->maxWallHeightInPath; + } + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER( + OpenSHC::Map::WallAndPitchState_Func::resetWallPlacementInfo, DAT_WallAndPitchState::ptr)(); + } + + int upY = y1 - y2; + int leftX = x1 - x2; + int downY = y2 - y1; + int rightX = x2 - x1; + int x = x1; + int y = y1; + int* translation = &DAT_ViewportRenderState::instance.translationMatrix[y1].addXgetTile; + do { + if (wallType == OpenSHC::Commands::M_MAPPER_STAIR && budget < 24) { + break; + } + if (placed >= tileCountUnk || wallCount > this->constructionTileCount) { + break; + } + placed++; + int const tile = *translation + x; + BOOLEnum towerNeighbours = FALSE; + if (wallType == OpenSHC::Commands::M_MAPPER_STAIR && (this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + break; + } + BOOLEnum applyWall = FALSE; + BOOLEnum overCrenel = FALSE; + if (wallType == OpenSHC::Commands::M_MAPPER_WALL && (this->LogicLayer[tile] & L_CRENEL) != 0) { + overCrenel = TRUE; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0 || this->DamageLayer[tile] != 0 || overCrenel) { + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL_MEMBER(OpenSHC::Map::WallAndPitchState_Func::addWallPlacementInfoForTile, + DAT_WallAndPitchState::ptr)(tile); + } + if (!overCrenel) { + applyWall = TRUE; + } + if (this->DamageLayer[tile] != 0 || overCrenel) { + this->DamageLayer[tile] = 0; + this->HeightLayer[tile] = this->DefaultHeightLayer[tile]; + if (overCrenel) { + this->LogicLayer[tile] + = this->LogicLayer[tile] & ~(L_CRENEL | L_CRENEL_VARIATIONUnk) | L_WALL_OR_GATEHOUSE; + } + } + + if (wallType == OpenSHC::Commands::M_MAPPER_WALL) { + this->HeightLayer[tile] += WALL_HIGH_HEIGHT; + } else if (wallType == OpenSHC::Commands::M_MAPPER_WOODWALL) { + this->HeightLayer[tile] += WALL_LOW_HEIGHT; + } else if (wallType == OpenSHC::Commands::M_MAPPER_CRENAL) { + this->LogicLayer[tile] |= L_CRENEL; + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::hasOnlyTowerNeighborsNoWalls, this)( + tile, y)) { + this->HeightLayer[tile] += WALL_LOW_CRENAL_HEIGHT; + towerNeighbours = TRUE; + } else { + this->HeightLayer[tile] += WALL_HIGH_CRENAL_HEIGHT; + } + if ((x & 1) != 0 && (y & 1) == 0) { + this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; + } else if ((x & 1) == 0 && (y & 1) != 0) { + this->LogicLayer[tile] |= L_CRENEL_VARIATIONUnk; + } + } else if (wallType == OpenSHC::Commands::M_MAPPER_STAIR) { + int const steps = budget - this->HeightLayer[tile] - 16; + if (steps > 0) { + this->LogicLayer[tile] |= L_STAIRS; + this->HeightLayer[tile] += steps; + } else { + applyWall = FALSE; + } + } + + if (applyWall || overCrenel) { + if (applyWall && !overCrenel) { + wallCount++; + this->LogicLayer[tile] + = this->LogicLayer[tile] & ~(L_UNKNOWN_WALL_RELATED | L_BOULDERS | L_PEBBLES | L_IRON) + | L_WALL_OR_GATEHOUSE; + short const unit = this->UnitLayer[tile]; + if (unit != 0 + && DAT_UnitsState::instance.units[unit].unitType == OpenSHC::Map::Units::UT_CHICKEN) { + DAT_UnitsState::instance.units[unit].state.generic + = OpenSHC::Map::Units::States::US_DISAPPEAR; + DAT_UnitsState::instance.units[unit].updateTickTracker = 0; + DAT_UnitsState::instance.units[unit].disappearFadeAlphaCountdown = 0; + } + if ((this->LogicLayer[tile] & L_PLAIN2_AND_PITCH) != 0) { + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->HeightLayer[tile] += 4; + } + if ((this->LogicLayer[tile] & L_TREE) != 0) { + int const organism = this->OrganismLayer[tile]; + if (organism < 2000) { + switch (DAT_LandscapeState::instance.trees[organism].treeType) { + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_A: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_B: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_C: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_D: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_E: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_A: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_B: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_C: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_D: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_E: + case OpenSHC::Map::Trees::TT_SHRUB_PIPE_CACTUS: + case OpenSHC::Map::Trees::TT_SHRUB_SUCCULENT: + case OpenSHC::Map::Trees::TT_SHRUB_CYCAD: + case OpenSHC::Map::Trees::TT_SHRUB_PRICKLYPEAR: + DAT_LandscapeState::instance.trees[organism].state = 3; + } + } + } + if (wallType == OpenSHC::Commands::M_MAPPER_WOODWALL || towerNeighbours) { + this->LogicLayer[tile] |= L_UNKNOWN_WALL_RELATED; + } + 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); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(7, x, y); + } + } + + int const stepX = x >= x2 ? leftX : rightX; + int const stepY = y >= y2 ? upY : downY; + if (wallType == OpenSHC::Commands::M_MAPPER_STAIR) { + if (stepX > stepY) { + if (x >= x2) { + leftX -= 1; + x -= 1; + rightX += 1; + } else { + leftX += 1; + x += 1; + rightX -= 1; + } + } else if (stepY > 0) { + if (y >= y2) { + y -= 1; + translation -= 3; + upY -= 1; + downY += 1; + } else { + y += 1; + translation += 3; + upY += 1; + downY -= 1; + } + } else { + overshoot -= 1; + } + } else { + if (stepX != 0) { + if (x >= x2) { + leftX -= 1; + x -= 1; + rightX += 1; + } else { + leftX += 1; + x += 1; + rightX -= 1; + } + } + if (stepY != 0) { + if (y >= y2) { + y -= 1; + translation -= 3; + upY -= 1; + downY += 1; + } else { + y += 1; + translation += 3; + upY += 1; + downY -= 1; + } + } + if (x == x2 && y == y2) { + overshoot -= 1; + } + } + if (budget >= 16) { + budget -= 16; + } + } while (x != x2 || y != y2 || overshoot != 0); + + if (wallType == OpenSHC::Commands::M_MAPPER_WOODWALL) { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processWallBuildingLoss, + DAT_BuildingsState::ptr)(playerID, 0, wallCount, 0); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processWallBuildingLoss, + DAT_BuildingsState::ptr)(playerID, wallCount, 0, 0); + } + 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/placeWheatfarm.cpp b/src/OpenSHC/Map/TileMapState/placeWheatfarm.cpp new file mode 100644 index 0000000000..aa3f9ea371 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeWheatfarm.cpp @@ -0,0 +1,90 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic1.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic2.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_WHEAT; + using OpenSHC::Map::LogicHelpers::L_NONE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00514F30 + void TileMapState::placeWheatfarm(int playerID, uint x, uint y, BuildingTypeShort buildingType, uint buildingSize, + int variation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, + DAT_BuildingsState::ptr)(playerID, x, y, averageHeight, (BuildingType)buildingType, 3, playerID, variation); + this->placedBuildingID = buildingID; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::markBuildingFootprintFlag, this)(x, y, 9); + + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.WheatFarmTiles[0]); i++) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i] + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .WheatFarmTiles[DAT_GameState::instance.playerDataArray[playerID] + .unkWheatFarmOrientation][i] + .y + + y] + .addXgetTile + + x + + DAT_TerrainDefinedData::instance + .WheatFarmTiles[DAT_GameState::instance.playerDataArray[playerID].unkWheatFarmOrientation][i] + .x; + } + DAT_GameState::instance.playerDataArray[playerID].unkWheatFarmOrientation++; + if (DAT_GameState::instance.playerDataArray[playerID].unkWheatFarmOrientation > 1) { + DAT_GameState::instance.playerDataArray[playerID].unkWheatFarmOrientation = 0; + } + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, 3); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setTerrain, this)( + playerID, tile, this->buildingY + y, 2, L_NONE, L2_THICK_SCRUB); + index++; + } while (index < this->constructionTileCount); + + for (int i = 0; i < countof(DAT_TerrainDefinedData::instance.WheatFarmTiles[0]); i++) { + int tile = DAT_BuildingsState::instance.buildings[buildingID].tileRefs[i]; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetTileAndClearMoat, this)(tile); + this->LogicLayer[tile] |= L_FARM_FIELD_WHEAT; + this->BuildingLayer[tile] = buildingID; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + + Game::Player::PlayerData const& player = DAT_GameState::instance.playerDataArray[playerID]; + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > player.availablePeasantsAtFire + && (player.populationCap <= player.currentPopulation || player.popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/placeWorkshopOrHovel.cpp b/src/OpenSHC/Map/TileMapState/placeWorkshopOrHovel.cpp new file mode 100644 index 0000000000..eaa87d8dcb --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/placeWorkshopOrHovel.cpp @@ -0,0 +1,62 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/UI/BottomLeftTextDisplayState.func.hpp" +#include "OpenSHC/DE/SHCDE/eTextSections.hpp" + +#include "OpenSHC/Globals/DAT_BottomLeftTextDisplayState.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00506BD0 + void TileMapState::placeWorkshopOrHovel(int playerID, uint x, uint y, BuildingTypeShort buildingType, + uint buildingSize, int variation, int averageHeight) + { + int index = 0; + int buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + DAT_BuildingsState::instance.buildings[buildingID].hovelVisualStyle + = DAT_GameState::instance.playerDataArray[playerID].hovelCountUpToEight; + if (buildingType == OpenSHC::Map::Buildings::BT_HOVEL) { + DAT_GameState::instance.playerDataArray[playerID].hovelCountUpToEight + = (DAT_GameState::instance.playerDataArray[playerID].hovelCountUpToEight + 1) % 7; + } + this->placedBuildingID = buildingID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + index++; + this->BuildingWasLayer[tile] = buildingType; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + if (playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_BuildingsState::instance.buildings[buildingID].buildingTypeBasedEmployeeCount + > DAT_GameState::instance.playerDataArray[playerID].availablePeasantsAtFire + && (DAT_GameState::instance.playerDataArray[playerID].populationCap + <= DAT_GameState::instance.playerDataArray[playerID].currentPopulation + || DAT_GameState::instance.playerDataArray[playerID].popularity < 5000)) { + MACRO_CALL_MEMBER(OpenSHC::UI::BottomLeftTextDisplayState_Func::setBottomLeftTextDisplayText, + DAT_BottomLeftTextDisplayState::ptr)(1, OpenSHC::DE::SHCDE::TEXT_PANEL_FEEDBACK, 1, 0, 100, 6000); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/prepareAreaForBuildingPlacement.cpp b/src/OpenSHC/Map/TileMapState/prepareAreaForBuildingPlacement.cpp new file mode 100644 index 0000000000..ba3dc6f3a0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/prepareAreaForBuildingPlacement.cpp @@ -0,0 +1,124 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game/GameStateStructures.func.hpp" +#include "OpenSHC/IO/LowLevelMemory.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingTilePlacementResult.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::Enums::BTPR_BLOCKED; + + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_APPLE; + + // FUNCTION: STRONGHOLDCRUSADER 0x005160C0 + BOOLEnum TileMapState::prepareAreaForBuildingPlacement( + int playerID, uint x, uint y, MappersEnumShort commandBuildingType, int buildingWidthOrHeight) + { + BOOLEnum result = FALSE; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::storeMinAndMaxHeightOfArea, this)( + x, y, buildingWidthOrHeight); + + int index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingWidthOrHeight); + uint const tileY = y + this->buildingY; + uint const tileX = x + this->buildingX; + if (tileX > MC_MAP_XY_LIMIT_INCLUSIVE) { + return FALSE; + } + if (tileY > MC_MAP_XY_LIMIT_INCLUSIVE) { + return FALSE; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[tileY * MC_MAP_XY_LIMIT + tileX] == 0) { + return FALSE; + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + return FALSE; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)( + tile, playerID, (MappersEnum)commandBuildingType, TRUE) + == BTPR_BLOCKED) { + return FALSE; + } + index++; + } while (index < this->constructionTileCount); + + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingWidthOrHeight); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + int buildingID = DAT_TileMapState::instance.BuildingLayer[tile]; + if (buildingID != 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_WOODCUTTERSHUT + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_OXTETHER + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_QUARRY + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_IRONMINE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_WHEATFARM + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_HOPFARM + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_APPLEFARM + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_DAIRYFARM) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::giveBackResourceForDestroyedBuilding, + DAT_BuildingsState::ptr)(buildingID, playerID, 50); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFromTerrain, DAT_TileMapState::ptr)( + buildingID); + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::updatePrimaryBuildingPlayerDataReferences, + DAT_GameState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_BuildingsState::instance.buildings[buildingID]), 0, + &DAT_BuildingsState::instance.buildings[buildingID]); + result = TRUE; + } + } else if ((DAT_TileMapState::instance.LogicLayer[tile] & L_FARM_FIELD_APPLE) != 0) { + buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::getFarmThatHasTile, DAT_BuildingsState::ptr)(tile); + if (buildingID != 0) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::giveBackResourceForDestroyedBuilding, + DAT_BuildingsState::ptr)(buildingID, playerID, 50); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearBuildingFromTerrain, DAT_TileMapState::ptr)( + buildingID); + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::updatePrimaryBuildingPlayerDataReferences, + DAT_GameState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_BuildingsState::instance.buildings[buildingID]), 0, + &DAT_BuildingsState::instance.buildings[buildingID]); + result = TRUE; + } + } + index++; + } while (index < this->constructionTileCount); + return result; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/prepareMap.cpp b/src/OpenSHC/Map/TileMapState/prepareMap.cpp new file mode 100644 index 0000000000..ac4a601be7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/prepareMap.cpp @@ -0,0 +1,181 @@ +#pragma warning(disable : 4996) + +#include "../TileMapState.func.hpp" + +#include "OpenSHC/AI/AIVState.func.hpp" +#include "OpenSHC/Game/GameStateStructures.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/MapPropertiesState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/TribesState.func.hpp" +#include "OpenSHC/Map/Units/TroopValueState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/WildlifeState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Text/UserTextHandler.func.hpp" +#include "OpenSHC/UI/HoveredState.func.hpp" +#include "OpenSHC/UI/MinimapViewState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_AIVState.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_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_HoveredState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" +#include "OpenSHC/Globals/DAT_MapPropertiesState.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_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_UserTextHandlerState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WallAndPitchState.hpp" +#include "OpenSHC/Globals/DAT_WildlifeState.hpp" +#include "OpenSHC/Globals/FilePackagerObj.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Game::GameMode; + using OpenSHC::Game::GameMode2; + + // FUNCTION: STRONGHOLDCRUSADER 0x00512450 + void TileMapState::prepareMap() + { + int savedX = DAT_ViewportRenderState::instance.viewportState.viewportX; + int savedY = DAT_ViewportRenderState::instance.viewportState.viewportY; + if (DAT_GameSynchronyState::instance.currentGameModeCopy_SEC_Section1106 + == OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER) { + DAT_GameSynchronyState::instance.currentGameMode = OpenSHC::Game::GM_SKIRMISH_SINGLE_PLAYER; + DAT_GameSynchronyState::instance.isHost = TRUE; + char* name = MACRO_CALL_MEMBER( + OpenSHC::Text::UserTextHandler_Func::getTextArrayPointer, DAT_UserTextHandlerState::ptr)(0); + strcpy(DAT_GameSynchronyState::instance.DAT_PlayerNames[1], name); + MACRO_CALL_MEMBER(OpenSHC::AI::AIVState_Func::syncAIPlayerNamesAndBuildIntervals, DAT_AIVState::ptr)(); + DAT_GameSynchronyState::instance.currentPlayerSlotID = 1; + } else if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_CAMPAIGN_MISSION) { + if (DAT_GameCore::instance.missionNumber1to20 < 16) { + DAT_GameSynchronyState::instance.currentGameMode = OpenSHC::Game::GM_SOLITARY; + } + } else if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_BUILDERUnk) { + DAT_GameSynchronyState::instance.currentGameMode = OpenSHC::Game::GM_SOLITARY; + } + + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::changeMapOrientation, this)( + (MapOrientation)this->mapOrientation); + 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); + DAT_ViewportRenderState::instance.viewportState.viewportX = savedX; + DAT_ViewportRenderState::instance.viewportState.viewportY = savedY; + MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::setViewportBasedOnMapSize, DAT_ViewportRenderState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::setTileSystemMemoryLookupArrays, + DAT_ViewportRenderState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::tweakValidTilesToExcludeMapBorders, + DAT_ViewportRenderState::ptr)(); + DAT_BuildingsState::instance.maxBuildingsCount = 2000; + DAT_UnitsState::instance.maxUnitCount = 2500; + DAT_PathFindingState::instance.maxClimbDataCount = 200; + DAT_EntityState::instance.maxEntityCount = 3000; + this->currentMoatCount = 16000; + DAT_LandscapeState::instance.maxTreeCount = 2000; + this->maxPitchDitchCount = 4000; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::resetHeightAndMapBorders, this)(this->mapSize); + 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::TileMapState_Func::setChangedLayerToThreeAndMapping0x40x40, this)(); + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + this->forceUpdateTextureTilemap = 1; + this->forceUpdateGFXLayers = 1; + this->forceUpdateMacroLayerFlag = 1; + this->field_0x55487c = 500; + + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::upgradeTribeArrayLayoutForMapVersion, + DAT_TribesState::ptr)((PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TroopValueState_Func::uselessFunction, DAT_TroopValueState::ptr)( + (PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::upgradeMapFormatForUnits, DAT_UnitsState::ptr)( + (PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::upgradeMapFormatLogicLayer, DAT_TileMapState::ptr)( + (PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::upgradeBuildingsForMapVersion, + DAT_BuildingsState::ptr)(FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::upgradeTreesAndRocksForMapVersion, + DAT_LandscapeState::ptr)((PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::Units::TribesState_Func::upgradeMapTribesState, DAT_TribesState::ptr)( + (PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::migrateGameStateForMapVersion, DAT_GameState::ptr)( + (PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::handleMapVersionUpgrade, DAT_EntityState::ptr)( + (PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::recountTotalOwnedMoats, this)(); + 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); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::updatePathLinkageLayerForAllBuildings, + DAT_BuildingsState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updateClimbData, DAT_PathFindingState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::clearBuildingValueWhenStateIsTwo, DAT_BuildingsState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::setCurrentTimeOnSomeTrees, DAT_LandscapeState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::resetWind, DAT_LandscapeState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::collectCliffEdgeTilesForClimbData, this)(); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearInvalidMoatEntries, this)(); + MACRO_CALL_MEMBER( + OpenSHC::Game::GameStateStructures_Func::initializeGameStateAfterMapLoad, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::MapPropertiesState_Func::sortEventsByDate, DAT_MapPropertiesState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::applyVersionUpgradeAccessibilityRecompute, + DAT_BuildingsState::ptr)((PackagedFileMagicNum)FilePackagerObj::instance.versionNumOfCurrentFileTypeUnk, + (PackagedFileMagicNum)FilePackagerObj::instance.packagerMapVersionNumUnk); + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updateSeparateAreaTileMap, DAT_PathFindingState::ptr)(1); + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::updatePathLinkageLayerForAllBuildings, + DAT_BuildingsState::ptr)(); + + for (int row = 0; row < countof(DAT_WildlifeState::instance.grid); row++) { + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateWildlifeGrid, DAT_WildlifeState::ptr)(row); + } + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateWildlife, DAT_WildlifeState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateSection1034Info, DAT_WildlifeState::ptr)(); + MACRO_CALL_MEMBER(OpenSHC::Map::WildlifeState_Func::updateNofFpoints, DAT_WildlifeState::ptr)(); + MACRO_CALL(OpenSHC::Map_Func::ResetSomeValuesFunctionUnk)(); + DAT_WallAndPitchState::instance.countdown = 0; + MACRO_CALL_MEMBER(OpenSHC::UI::HoveredState_Func::clearHoveredState, DAT_HoveredState::ptr)(); + DAT_GameCore::instance.gamePausedLogical = 0xffffffff; + MACRO_CALL_MEMBER(OpenSHC::Game::GameStateStructures_Func::processGameTick, DAT_GameState::ptr)(); + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updateSeparateAreaTileMap, DAT_PathFindingState::ptr)(1); + 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); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/processDamageToBuilding.cpp b/src/OpenSHC/Map/TileMapState/processDamageToBuilding.cpp new file mode 100644 index 0000000000..8d266bcde2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/processDamageToBuilding.cpp @@ -0,0 +1,541 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/AI/AICState.func.hpp" +#include "OpenSHC/Audio/MSS/SoundSystem.func.hpp" +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Map/Version.func.hpp" +#include "OpenSHC/Random/RNG.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_AICState.hpp" +#include "OpenSHC/Globals/DAT_BuildingDefinedData.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_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_SoundSystemState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_TroopValueState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/SEC_RNG.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_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::DE::SHCDE::eSFX; + using OpenSHC::Game::GameMode; + using OpenSHC::Map::Entities::EntityType; + 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::Units::States::UnitState; + + // FUNCTION: STRONGHOLDCRUSADER 0x00516B80 + BOOLEnum TileMapState::processDamageToBuilding(int tile, uint xPosition, uint yPosition, int damageUnk, + int suppressDamage, int playerID, BOOLEnum aiBuildDelayRelated, int unitID) + { + int replaced = 0; + BOOLEnum volatile destroyed = FALSE; + BOOLEnum spareOwnTeam = FALSE; + if (playerID < 0) { + playerID = -playerID; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] == -1) { + spareOwnTeam = TRUE; + } + } + + uint logic = this->LogicLayer[tile]; + if ((logic & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 || this->BuildingLayer[tile] != 0) { + int buildingID = this->BuildingLayer[tile]; + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_NONE) { + return TRUE; + } + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState + == OpenSHC::Map::Buildings::BLS_REMOVE) { + return TRUE; + } + if (DAT_BuildingsState::instance.buildings[buildingID].currentHealth == 0) { + return TRUE; + } + DAT_GameCore::instance.cowPoisonTrackerUnk += damageUnk * 10; + if (DAT_BuildingDefinedData::instance + .BuildingTypeHasHealth[DAT_BuildingsState::instance.buildings[buildingID].buildingType] + == 0) { + return TRUE; + } + if ((this->LogicLayer[tile] + & (L_FARM_FIELD_WHEAT | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY)) + != 0) { + return TRUE; + } + if (spareOwnTeam != FALSE + && DAT_GameState::instance.mapAndTime.playerTeams[playerID] + == DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[buildingID].owner]) { + return FALSE; + } + DAT_BuildingsState::instance.buildings[buildingID].currentHealth -= damageUnk; + + if (aiBuildDelayRelated == TRUE + && (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSESMALL)) { + int bridge = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findParticularBuilding, + DAT_BuildingsState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, + DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight, + OpenSHC::Map::Buildings::BT_DRAWBRIDGE, 0); + if (bridge != 0) { + if (DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[bridge].buildingType] + != 0) { + this->showNoRubbleWhenDestroyingBuilding = FALSE; + } else { + this->showNoRubbleWhenDestroyingBuilding = TRUE; + } + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, DAT_BuildingsState::ptr)(bridge); + int second = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findParticularBuilding, + DAT_BuildingsState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, + DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight, + OpenSHC::Map::Buildings::BT_DRAWBRIDGE, bridge); + if (second != 0) { + this->showNoRubbleWhenDestroyingBuilding + = DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[second].buildingType] + == 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(second); + } + } + } + + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + 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: + DAT_GameState::instance.playerDataArray[DAT_BuildingsState::instance.buildings[buildingID].owner] + .defensesDamagedByPlayer = playerID; + break; + default: + break; + } + if (unitID != 0) { + if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[buildingID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk += 1; + } else { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk = 0; + } + } + + short remaining = DAT_BuildingsState::instance.buildings[buildingID].currentHealth; + if (remaining <= 0) { + if (DAT_BuildingsState::instance.buildings[buildingID].owner + == DAT_GameSynchronyState::instance.currentPlayerSlotID) { + MACRO_CALL(OpenSHC::Map::Version_Func::UpdateDestroyedBuildingCountData)(1); + } + if (aiBuildDelayRelated == TRUE + && DAT_GameState::instance.playerDataArray[DAT_BuildingsState::instance.buildings[buildingID].owner] + .resourceRebuildDelay + == 0) { + DAT_GameState::instance.playerDataArray[DAT_BuildingsState::instance.buildings[buildingID].owner] + .resourceRebuildDelay = 1; + } + int owner = DAT_BuildingsState::instance.buildings[buildingID].owner; + int destroyedType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + if (destroyedType != OpenSHC::Map::Buildings::BT_UNKNOWN3 + && (destroyedType <= OpenSHC::Map::Buildings::BT_UNKNOWN4 + || destroyedType > OpenSHC::Map::Buildings::BT_UNKNOWN6)) { + DAT_GameSynchronyState::instance.finalResults.finalBuildingsBurned[playerID] += 1; + DAT_GameSynchronyState::instance.finalResults.finalBuildingsDestroyedWeighted[playerID] + += DAT_BuildingDefinedData::instance.BuildingDestroyedScoreWeight[destroyedType]; + DAT_GameSynchronyState::instance.finalResults.finalBuidingsDestroyed[owner] += 1; + DAT_GameState::instance.playerDataArray[owner].attackedByPlayer[playerID].buildingsDestroyed += 1; + } + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_OILSMELTER: + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + 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: + MACRO_CALL_MEMBER(OpenSHC::AI::AICState_Func::playAnger2BikFromPlayerToPlayer, DAT_AICState::ptr)( + owner, playerID); + break; + default: + MACRO_CALL_MEMBER(OpenSHC::AI::AICState_Func::playVictory2BikFromPlayerToPlayer, DAT_AICState::ptr)( + owner, playerID); + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY + && playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_GameState::instance.mapAndTime.playerTeams[owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_TOWER4 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_TOWER5 + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_GATEHOUSELARGE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_CHURCH + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_CATHEDRAL) + && MACRO_CALL_MEMBER( + OpenSHC::Audio::MSS::SoundSystem_Func::shouldSoundXNotBePlaying, DAT_SoundSystemState::ptr)() + == FALSE) { + MACRO_CALL_MEMBER(OpenSHC::Random::RNG_Func::nextRandomNumber1, SEC_RNG::ptr)(); + if (DAT_GameCore::instance.genieVoiceActive != FALSE) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_Genie_36_wav_005ab92c); + } + } + + BOOLEnum destroyNormally = TRUE; + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_TOWER1: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 25); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + int towerX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + int towerY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, towerX, towerY, OpenSHC::Commands::M_MAPPER_TOWER1_DESTROYED, 3, 15); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + towerX, towerY, OpenSHC::DE::SHCDE::FX_TOWER_SMASH); + replaced = 1; + destroyed = TRUE; + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER2: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + int towerX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + int towerY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, towerX, towerY, OpenSHC::Commands::M_MAPPER_TOWER2_DESTROYED, 4, 15); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + towerX, towerY, OpenSHC::DE::SHCDE::FX_TOWER_SMASH); + replaced = 1; + destroyed = TRUE; + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER3: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + int towerX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + int towerY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, towerX, towerY, OpenSHC::Commands::M_MAPPER_TOWER3_DESTROYED, 5, 15); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + towerX, towerY, OpenSHC::DE::SHCDE::FX_TOWER_SMASH); + replaced = 1; + destroyed = TRUE; + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER4: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + int towerX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + int towerY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, towerX, towerY, OpenSHC::Commands::M_MAPPER_TOWER4_DESTROYED, 6, 15); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + towerX, towerY, OpenSHC::DE::SHCDE::FX_TOWER_SMASH); + replaced = 1; + destroyed = TRUE; + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER5: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + int towerX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + int towerY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, towerX, towerY, OpenSHC::Commands::M_MAPPER_TOWER5_DESTROYED, 6, 15); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + towerX, towerY, OpenSHC::DE::SHCDE::FX_TOWER_SMASH); + replaced = 1; + destroyed = TRUE; + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_OILSMELTER: { + int oilAmount = DAT_BuildingsState::instance.buildings[buildingID] + .resources[OpenSHC::Game::Resources::RT_PITCH]; + if (oilAmount == 0) { + break; + } + int smelterX = DAT_BuildingsState::instance.buildings[buildingID].x; + int smelterOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + uint smelterTile = DAT_BuildingsState::instance.buildings[buildingID].currentTilePositionAdjusted; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + int smelterY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, + DAT_BuildingsState::ptr)(buildingID); + if (oilAmount <= 4) { + MACRO_CALL(OpenSHC::Map::Entities_Func::SetPlaceOnFire)(smelterOwner, smelterX * 8 + 16, + smelterY * 8 + 16, DAT_TileMapState::instance.HeightLayer[smelterTile], 3); + } else { + MACRO_CALL(OpenSHC::Map::Entities_Func::SetPlaceOnFire)(smelterOwner, smelterX * 8 + 16, + smelterY * 8 + 16, DAT_TileMapState::instance.HeightLayer[smelterTile], 5); + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, smelterOwner, 0, smelterX * 8 + 16, smelterY * 8 + 16, + DAT_TileMapState::instance.HeightLayer[smelterTile], 0, 0, 0, + OpenSHC::Map::Entities::EntityTypeInt__ET_EXPLOSION, 0); + } + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + smelterX, smelterY, OpenSHC::DE::SHCDE::FX_IGNITE_PITCH); + destroyed = TRUE; + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: { + int bridge = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findParticularBuilding, + DAT_BuildingsState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, + DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight, + OpenSHC::Map::Buildings::BT_DRAWBRIDGE, 0); + if (bridge != 0) { + if (DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[bridge].buildingType] + != 0) { + this->showNoRubbleWhenDestroyingBuilding = FALSE; + } else { + this->showNoRubbleWhenDestroyingBuilding = TRUE; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(bridge); + int second + = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findParticularBuilding, + DAT_BuildingsState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, + DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight, + OpenSHC::Map::Buildings::BT_DRAWBRIDGE, bridge); + if (second != 0) { + this->showNoRubbleWhenDestroyingBuilding + = DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[second].buildingType] + == 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(second); + } + } + int gateX = DAT_BuildingsState::instance.buildings[buildingID].x; + int gateY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + this->showNoRubbleWhenDestroyingBuilding + = DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[buildingID].buildingType] + == 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + gateX, gateY, OpenSHC::DE::SHCDE::FX_TOWER_SMASH); + destroyed = TRUE; + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TUNNEL: { + int tunneller = DAT_BuildingsState::instance.buildings[buildingID].unitRefID; + if (DAT_UnitsState::instance.units[tunneller].state.generic + != (OpenSHC::Map::Units::States::US_STAND_UPUnk | OpenSHC::Map::Units::States::US_IDLEUnk)) { + DAT_UnitsState::instance.units[tunneller].totalSizeOfPathPlan + = DAT_UnitsState::instance.units[tunneller].currentIndexInPathPlan; + MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::applyTunnelDamageAlongPathPlan, + DAT_UnitsState::ptr)(tunneller); + } + DAT_UnitsState::instance.units[tunneller].state.generic = OpenSHC::Map::Units::States::US_DISAPPEAR; + DAT_UnitsState::instance.units[tunneller].disappearFadeAlphaCountdown = 32; + DAT_UnitsState::instance.units[tunneller].updateTickTracker = 32; + } break; + case OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED: { + int rider = DAT_BuildingsState::instance.buildings[buildingID].unitRefID; + if (rider != 0 + && DAT_BuildingsState::instance.buildings[buildingID].unitRefUID + == DAT_UnitsState::instance.units[rider].uid) { + DAT_UnitsState::instance.units[rider].state.generic = OpenSHC::Map::Units::States::US_DISAPPEAR; + DAT_UnitsState::instance.units[rider].disappearFadeAlphaCountdown = 0; + DAT_UnitsState::instance.units[rider].updateTickTracker = 0; + DAT_UnitsState::instance.units[rider].workplaceBuildingID_1 = 0; + } + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, + DAT_BuildingsState::ptr)(buildingID); + destroyed = TRUE; + destroyNormally = FALSE; + } break; + } + if (destroyNormally != FALSE) { + int rubbleType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + int rubbleOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + this->showNoRubbleWhenDestroyingBuilding + = DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed[rubbleType] == 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, OpenSHC::DE::SHCDE::FX_BUILDING_SMASH); + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY + && playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_GameState::instance.mapAndTime.playerTeams[rubbleOwner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && DAT_GameCore::instance.genieVoiceActive != FALSE) { + if (rubbleType == OpenSHC::Map::Buildings::BT_GRANARY + || rubbleType == OpenSHC::Map::Buildings::BT_ARMORY) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_Genie_23_wav_005ab91c); + } + if (rubbleType == OpenSHC::Map::Buildings::BT_MERCENARYPOST + || rubbleType == OpenSHC::Map::Buildings::BT_BARRACKS) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_Genie_24_wav_005ab90c); + } + } + destroyed = TRUE; + } + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED) { + int rider = DAT_BuildingsState::instance.buildings[buildingID].unitRefID; + if (rider != 0 + && DAT_BuildingsState::instance.buildings[buildingID].unitRefUID + == DAT_UnitsState::instance.units[rider].uid + && DAT_BuildingsState::instance.buildings[buildingID].maxHealth != 0) { + DAT_UnitsState::instance.units[rider].health + = (remaining * DAT_UnitsState::instance.units[rider].maxHealth) + / DAT_BuildingsState::instance.buildings[buildingID].maxHealth; + } + } + } else { + if ((logic & L_WALL_OR_GATEHOUSE) == 0) { + destroyed = TRUE; + } else { + if ((logic & L_STOCKPILEUnk) != 0) { + return FALSE; + } + int wallOwner = (this->WallOwnerLayer[tile] & OpenSHC::Map::LogicHelpers::WO_OWNER_MASK) + 1; + if (spareOwnTeam != FALSE + && DAT_GameState::instance.mapAndTime.playerTeams[playerID] + == DAT_GameState::instance.mapAndTime.playerTeams[wallOwner]) { + return FALSE; + } + DAT_GameState::instance.playerDataArray[wallOwner].defensesDamagedByPlayer = playerID; + if (unitID != 0) { + if (DAT_GameState::instance.mapAndTime.playerTeams[wallOwner] + == DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk += 1; + } else { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk = 0; + } + } + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::countLogicPropertyInSurroundingTiles, this)( + tile, yPosition, L_KEEP_NON_MANOR_HOUSE | L_WALL_OR_GATEHOUSE); + if (this->DAT_CardinalTilesAroundTile <= 1) { + damageUnk += damageUnk / 2; + } else if (this->DAT_CardinalTilesAroundTile > 2) { + damageUnk /= 2; + } + if (suppressDamage != 0) { + damageUnk = 0; + } + DAT_TroopValueState::instance.attackInfo.buildingDamageEventCount += 1; + DAT_GameCore::instance.cowPoisonTrackerUnk += damageUnk * 10; + if (suppressDamage == 0 && (this->LogicLayer[tile] & L_UNKNOWN_WALL_RELATED) == 0 + && this->DamageLayer[tile] == 0 && this->HeightLayer[tile] > this->DefaultHeightLayer[tile] + 60) { + this->HeightLayer[tile] -= 20; + } + for (int hit = 0; hit < damageUnk; hit++) { + if (this->HeightLayer[tile] <= this->DefaultHeightLayer[tile]) { + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, + DAT_EntityState::ptr)(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; + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + destroyed = TRUE; + break; + } + this->HeightLayer[tile] -= 1; + if (this->DamageLayer[tile] < 200) { + this->DamageLayer[tile] += 1; + } + } + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(yPosition, tile); + } + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(7, xPosition, yPosition); + BOOLEnum const result = destroyed; + if (replaced != 0) { + return FALSE; + } + return result; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/processEntityDamageToBuildingCollateral.cpp b/src/OpenSHC/Map/TileMapState/processEntityDamageToBuildingCollateral.cpp new file mode 100644 index 0000000000..c3b57d7fef --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/processEntityDamageToBuildingCollateral.cpp @@ -0,0 +1,401 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/AI/AICState.func.hpp" +#include "OpenSHC/Audio/SFX/SFXState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Entities.func.hpp" +#include "OpenSHC/Map/Entities/EntityState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Units/UnitsState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eSFX.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/Resources/ResourceType.hpp" +#include "OpenSHC/Map/Buildings/BuildingLogicalState.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Entities/EntityType.hpp" +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" +#include "OpenSHC/string-literals.hpp" + +#include "OpenSHC/Globals/DAT_AICState.hpp" +#include "OpenSHC/Globals/DAT_BuildingDefinedData.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_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_SFXState.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.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_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::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_UNKNOWN_WALL_RELATED; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::DE::SHCDE::eSFX; + using OpenSHC::Game::GameMode; + using OpenSHC::Map::Entities::EntityType; + using OpenSHC::Map::Units::States::UnitState; + + // FUNCTION: STRONGHOLDCRUSADER 0x00517790 + void TileMapState::processEntityDamageToBuildingCollateral( + int tile, uint x, int y, int damage, int playerID, undefined4 unused, int unitID) + { + int baseTile = tile; + int baseY = y; + BOOLEnum spareOwnTeam = FALSE; + if (playerID < 0) { + playerID = -playerID; + if (DAT_GameSynchronyState::instance.currentPlayerFullIDArray[playerID] == -1) { + spareOwnTeam = TRUE; + } + } + + for (int index = 0; index < 9; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + FALSE, index, &tile, &y, baseTile, baseY); + int const brushTile = *(int volatile*)&tile; + int const logic = this->LogicLayer[brushTile]; + if ((logic & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) == 0 && this->BuildingLayer[brushTile] == 0) { + if ((logic & L_WALL_OR_GATEHOUSE) == 0 || (logic & L_STOCKPILEUnk) != 0) { + continue; + } + int wallOwner = (this->WallOwnerLayer[brushTile] & OpenSHC::Map::LogicHelpers::WO_OWNER_MASK) + 1; + if (spareOwnTeam != FALSE + && DAT_GameState::instance.mapAndTime.playerTeams[playerID] + == DAT_GameState::instance.mapAndTime.playerTeams[wallOwner]) { + continue; + } + DAT_GameState::instance.playerDataArray[wallOwner].defensesDamagedByPlayer = playerID; + if (unitID != 0) { + if (DAT_GameState::instance.mapAndTime.playerTeams[wallOwner] + == DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk += 1; + } else { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk = 0; + } + } + DAT_GameCore::instance.cowPoisonTrackerUnk += damage * 10; + for (int hit = 0; hit < damage; hit++) { + if (*(byte volatile*)&this->HeightLayer[brushTile] <= this->DefaultHeightLayer[brushTile]) { + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, + DAT_EntityState::ptr)(brushTile); + this->LogicLayer[brushTile] &= ~( + L_WALL_OR_GATEHOUSE | L_CRENEL | L_STAIRS | L_UNKNOWN_WALL_RELATED | L_CRENEL_VARIATIONUnk); + byte& height = this->HeightLayer[brushTile]; + height = this->DefaultHeightLayer[brushTile]; + this->DamageLayer[brushTile] = 0; + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, brushTile); + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + DAT_TileMapState::instance.field_0x554a30 = 1; + break; + } + this->HeightLayer[brushTile] -= 1; + char const& damageLevel = this->DamageLayer[brushTile]; + if (damageLevel < 200) { + this->DamageLayer[brushTile] += 1; + } + } + continue; + } + + int buildingID = this->BuildingLayer[brushTile]; + if (DAT_BuildingsState::instance.buildings[buildingID].logicalState == OpenSHC::Map::Buildings::BLS_NONE + || DAT_BuildingsState::instance.buildings[buildingID].logicalState + == OpenSHC::Map::Buildings::BLS_REMOVE) { + continue; + } + if (DAT_BuildingsState::instance.buildings[buildingID].currentHealth == 0) { + continue; + } + int buildingType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + if (DAT_BuildingDefinedData::instance.BuildingTypeHasHealth[buildingType] == 0) { + continue; + } + if ((logic & (L_FARM_FIELD_WHEAT | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY)) != 0 + || (logic & L_STOCKPILEUnk) != 0) { + continue; + } + if (spareOwnTeam != FALSE + && DAT_GameState::instance.mapAndTime.playerTeams[playerID] + == DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[buildingID].owner]) { + continue; + } + + DAT_BuildingsState::instance.buildings[buildingID].currentHealth -= damage; + DAT_GameCore::instance.cowPoisonTrackerUnk += damage * 10; + switch (buildingType) { + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + 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: + DAT_GameState::instance.playerDataArray[DAT_BuildingsState::instance.buildings[buildingID].owner] + .defensesDamagedByPlayer = playerID; + } + if (unitID != 0) { + if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[buildingID].owner] + == DAT_GameState::instance.mapAndTime.playerTeams[playerID]) { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk += 1; + } else { + DAT_UnitsState::instance.units[unitID].friendlyFireCounterUnk = 0; + } + } + if (DAT_BuildingsState::instance.buildings[buildingID].currentHealth > 0) { + continue; + } + + if (buildingType != OpenSHC::Map::Buildings::BT_UNKNOWN3 + && (buildingType <= OpenSHC::Map::Buildings::BT_UNKNOWN4 + || buildingType > OpenSHC::Map::Buildings::BT_UNKNOWN6)) { + int owner = DAT_BuildingsState::instance.buildings[buildingID].owner; + DAT_GameSynchronyState::instance.finalResults.finalBuildingsBurned[playerID] += 1; + DAT_GameSynchronyState::instance.finalResults.finalBuidingsDestroyed[owner] += 1; + DAT_GameState::instance.playerDataArray[owner].attackedByPlayer[playerID].buildingsDestroyed += 1; + } + switch (buildingType) { + case OpenSHC::Map::Buildings::BT_OILSMELTER: + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + 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: + MACRO_CALL_MEMBER(OpenSHC::AI::AICState_Func::playAnger2BikFromPlayerToPlayer, DAT_AICState::ptr)( + DAT_BuildingsState::instance.buildings[buildingID].owner, playerID); + break; + default: + MACRO_CALL_MEMBER(OpenSHC::AI::AICState_Func::playVictory2BikFromPlayerToPlayer, DAT_AICState::ptr)( + DAT_BuildingsState::instance.buildings[buildingID].owner, playerID); + } + + int destroyedX; + int destroyedY; + BOOLEnum destroyNormally = TRUE; + switch (DAT_BuildingsState::instance.buildings[buildingID].buildingType) { + case OpenSHC::Map::Buildings::BT_TOWER1: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 25); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + destroyedX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + destroyedY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, destroyedX, destroyedY, OpenSHC::Commands::M_MAPPER_TOWER1_DESTROYED, 3, 15); + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER2: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + destroyedX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + destroyedY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, destroyedX, destroyedY, OpenSHC::Commands::M_MAPPER_TOWER2_DESTROYED, 4, 15); + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER3: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + destroyedX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + destroyedY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, destroyedX, destroyedY, OpenSHC::Commands::M_MAPPER_TOWER3_DESTROYED, 5, 15); + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER4: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + destroyedX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + destroyedY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, destroyedX, destroyedY, OpenSHC::Commands::M_MAPPER_TOWER4_DESTROYED, 6, 15); + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TOWER5: { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + int towerOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + destroyedX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + destroyedY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::placeBuilding, this)( + towerOwner, destroyedX, destroyedY, OpenSHC::Commands::M_MAPPER_TOWER5_DESTROYED, 6, 15); + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_OILSMELTER: { + int oilAmount + = DAT_BuildingsState::instance.buildings[buildingID].resources[OpenSHC::Game::Resources::RT_PITCH]; + if (oilAmount == 0) { + break; + } + int smelterOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + uint smelterTile = DAT_BuildingsState::instance.buildings[buildingID].currentTilePositionAdjusted; + destroyedX = DAT_BuildingsState::instance.buildings[buildingID].x; + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + destroyedY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + if (oilAmount <= 4) { + MACRO_CALL(OpenSHC::Map::Entities_Func::SetPlaceOnFire)(smelterOwner, destroyedX * 8 + 16, + destroyedY * 8 + 16, DAT_TileMapState::instance.HeightLayer[smelterTile], 3); + } else { + MACRO_CALL(OpenSHC::Map::Entities_Func::SetPlaceOnFire)(smelterOwner, destroyedX * 8 + 16, + destroyedY * 8 + 16, DAT_TileMapState::instance.HeightLayer[smelterTile], 5); + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::spawnProjectileEntity, + DAT_EntityState::ptr)(0, smelterOwner, 0, destroyedX * 8 + 16, destroyedY * 8 + 16, + DAT_TileMapState::instance.HeightLayer[smelterTile], 0, 0, 0, + OpenSHC::Map::Entities::EntityTypeInt__ET_EXPLOSION, 0); + } + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + destroyedX, destroyedY, OpenSHC::DE::SHCDE::FX_IGNITE_PITCH); + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: { + int bridge = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findParticularBuilding, + DAT_BuildingsState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, + DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight, + OpenSHC::Map::Buildings::BT_DRAWBRIDGE, 0); + if (bridge != 0) { + if (DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[bridge].buildingType] + != 0) { + this->showNoRubbleWhenDestroyingBuilding = FALSE; + } else { + this->showNoRubbleWhenDestroyingBuilding = TRUE; + } + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, DAT_BuildingsState::ptr)(bridge); + int second = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::findParticularBuilding, + DAT_BuildingsState::ptr)(DAT_BuildingsState::instance.buildings[buildingID].owner, + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, + DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight, + OpenSHC::Map::Buildings::BT_DRAWBRIDGE, bridge); + if (second != 0) { + this->showNoRubbleWhenDestroyingBuilding + = DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[second].buildingType] + == 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, + DAT_BuildingsState::ptr)(second); + } + } + destroyedX = DAT_BuildingsState::instance.buildings[buildingID].x; + destroyedY = DAT_BuildingsState::instance.buildings[buildingID].y; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processDamageToUnitsOnBuilding, + DAT_BuildingsState::ptr)(buildingID, 50); + this->showNoRubbleWhenDestroyingBuilding + = DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed + [DAT_BuildingsState::instance.buildings[buildingID].buildingType] + == 0; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + destroyedX, destroyedY, OpenSHC::DE::SHCDE::FX_TOWER_SMASH); + destroyNormally = FALSE; + } break; + case OpenSHC::Map::Buildings::BT_TUNNEL: { + int tunneller = DAT_BuildingsState::instance.buildings[buildingID].unitRefID; + if (DAT_UnitsState::instance.units[tunneller].state.generic + != (OpenSHC::Map::Units::States::US_STAND_UPUnk | OpenSHC::Map::Units::States::US_IDLEUnk)) { + DAT_UnitsState::instance.units[tunneller].totalSizeOfPathPlan + = DAT_UnitsState::instance.units[tunneller].currentIndexInPathPlan; + MACRO_CALL_MEMBER(OpenSHC::Map::Units::UnitsState_Func::applyTunnelDamageAlongPathPlan, + DAT_UnitsState::ptr)(tunneller); + } + DAT_UnitsState::instance.units[tunneller].state.generic = OpenSHC::Map::Units::States::US_DISAPPEAR; + DAT_UnitsState::instance.units[tunneller].disappearFadeAlphaCountdown = 32; + DAT_UnitsState::instance.units[tunneller].updateTickTracker = 32; + } break; + case OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED: { + int rider = DAT_BuildingsState::instance.buildings[buildingID].unitRefID; + if (rider != 0 + && DAT_BuildingsState::instance.buildings[buildingID].unitRefUID + == DAT_UnitsState::instance.units[rider].uid) { + DAT_UnitsState::instance.units[rider].state.generic = OpenSHC::Map::Units::States::US_DISAPPEAR; + DAT_UnitsState::instance.units[rider].disappearFadeAlphaCountdown = 0; + DAT_UnitsState::instance.units[rider].updateTickTracker = 0; + DAT_UnitsState::instance.units[rider].workplaceBuildingID_1 = 0; + } + DAT_BuildingsState::instance.buildings[buildingID].noRubble = 0; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::deleteBuilding, DAT_BuildingsState::ptr)(buildingID); + destroyNormally = FALSE; + } break; + } + if (destroyNormally != FALSE) { + int destroyedType = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + int destroyedOwner = DAT_BuildingsState::instance.buildings[buildingID].owner; + this->showNoRubbleWhenDestroyingBuilding + = DAT_BuildingDefinedData::instance.BuildingShowRubbleWhenDestroyed[destroyedType] == 0; + MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuilding, DAT_BuildingsState::ptr)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)( + DAT_BuildingsState::instance.buildings[buildingID].x, + DAT_BuildingsState::instance.buildings[buildingID].y, OpenSHC::DE::SHCDE::FX_BUILDING_SMASH); + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY + && playerID == DAT_GameSynchronyState::instance.currentPlayerSlotID + && DAT_GameState::instance.mapAndTime.playerTeams[destroyedOwner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && DAT_GameCore::instance.genieVoiceActive != FALSE) { + if (destroyedType == OpenSHC::Map::Buildings::BT_GRANARY + || destroyedType == OpenSHC::Map::Buildings::BT_ARMORY) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_Genie_23_wav_005ab91c); + } + if (destroyedType == OpenSHC::Map::Buildings::BT_MERCENARYPOST + || destroyedType == OpenSHC::Map::Buildings::BT_BARRACKS) { + MACRO_CALL_MEMBER(OpenSHC::Audio::SFX::SFXState_Func::playWAVSFX, DAT_SFXState::ptr)( + s_Genie_24_wav_005ab90c); + } + } + } + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(9, x, baseY); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/propagateCliffEdgeFlagFromNeighbor.cpp b/src/OpenSHC/Map/TileMapState/propagateCliffEdgeFlagFromNeighbor.cpp new file mode 100644 index 0000000000..8d61e52f87 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/propagateCliffEdgeFlagFromNeighbor.cpp @@ -0,0 +1,54 @@ +#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::L2_OASIS_GRASS; + using OpenSHC::Map::LogicHelpers::L2_STONES_OR_DRIVEN_SANDUnk; + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_RIVER; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC280 + void TileMapState::propagateCliffEdgeFlagFromNeighbor(int tile, int x, int y) + { + int const height = this->HeightLayer[tile]; + if (this->Logic2Layer[tile] != 0) { + return; + } + + for (int index = 0; index < countof(DAT_TerrainDefinedData::instance.field_0x372c); index++) { + XYPair offset; + offset.x = DAT_TerrainDefinedData::instance.field_0x372c[index].x; + offset.y = DAT_TerrainDefinedData::instance.field_0x372c[index].y; + uint const neighbourY = offset.y + y; + uint const neighbourX = offset.x + x; + if (neighbourX > MC_MAP_XY_LIMIT_INCLUSIVE || neighbourY > MC_MAP_XY_LIMIT_INCLUSIVE) { + continue; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[neighbourY * MC_MAP_XY_LIMIT + neighbourX] + == 0) { + continue; + } + int const neighbour + = DAT_ViewportRenderState::instance.translationMatrix[neighbourY].addXgetTile + offset.x + x; + if ((this->LogicLayer[neighbour] & L_RIVER) == 0) { + continue; + } + if ((this->Logic2Layer[neighbour] & (L2_OASIS_GRASS | L2_STONES_OR_DRIVEN_SANDUnk)) == 0) { + continue; + } + if (this->HeightLayer[neighbour] < height) { + continue; + } + this->Logic2Layer[tile] = L2_THICK_SCRUB; + return; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/raiseLand.cpp b/src/OpenSHC/Map/TileMapState/raiseLand.cpp new file mode 100644 index 0000000000..9ceb3d10b7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/raiseLand.cpp @@ -0,0 +1,93 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.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_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_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00501D90 + void TileMapState::raiseLand(int tile, int y, uint brush, int change) + { + int const baseTile = tile; + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[brush]; + int const baseY = y; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, baseY); + int const brushTile = *(int volatile*)&tile; + uint const logic = this->LogicLayer[brushTile]; + if ((logic & (L_BORDER | L_BORDER_EDGE)) != 0) { + continue; + } + if ((logic & (L_SEA | L_MARSH)) != 0 && this->editorAffectType == 0) { + continue; + } + if ((logic & (L_SEA | L_MARSH)) == 0 && this->editorAffectType == 1) { + continue; + } + if ((logic & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_MOAT_DUG_OR_PLANNED | L_KEEP_NON_MANOR_HOUSE | L_MOAT)) + != 0) { + continue; + } + if (this->BuildingLayer[brushTile] != 0) { + continue; + } + int minHeight; + int maxHeight; + if ((logic & L_SEA) != 0) { + minHeight = 0; + maxHeight = 0; + } else if ((logic & (L_SEA | L_MARSH | L_MOAT)) != 0) { + minHeight = 0; + maxHeight = 20; + } else { + minHeight = 8; + maxHeight = 128; + } + *(uint volatile*)&this->LogicLayer[brushTile] &= ~L_ROCKY; + if ((this->LogicLayer[brushTile] & L_RIVER) != 0) { + this->HeightLayer[brushTile] += 8; + } + this->ChangedLayer[brushTile] = 2; + byte const& height = this->HeightLayer[brushTile]; + if (height <= minHeight) { + this->HeightLayer[brushTile] = minHeight; + } + if (height > 0 || change >= 0) { + this->HeightLayer[brushTile] += change; + this->Logic2Layer[brushTile] = 0; + } + if (height < minHeight) { + this->HeightLayer[brushTile] = minHeight; + } + if (height > maxHeight) { + this->HeightLayer[brushTile] = maxHeight; + } + this->DefaultHeightLayer[brushTile] = height; + if ((this->LogicLayer[brushTile] & L_RIVER) != 0) { + this->HeightLayer[brushTile] -= 8; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, brushTile); + } + this->forceUpdateTextureTilemap = 1; + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/reassignWallOwnershipForPlayer.cpp b/src/OpenSHC/Map/TileMapState/reassignWallOwnershipForPlayer.cpp new file mode 100644 index 0000000000..1e67eaeb24 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/reassignWallOwnershipForPlayer.cpp @@ -0,0 +1,33 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LogicHelpers/WallOwner.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::WO_OWNER_MASK; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9000 + void TileMapState::reassignWallOwnershipForPlayer(int playerID, int newOwner) + { + for (int tile = 0; tile < countof(this->LogicLayer); ++tile) { + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) == 0) { + continue; + } + int const building = this->BuildingLayer[tile]; + if (building != 0) { + if (DAT_BuildingsState::instance.buildings[building].owner != newOwner) { + continue; + } + } else if ((this->WallOwnerLayer[tile] & WO_OWNER_MASK) + 1 != playerID) { + continue; + } + this->WallOwnerLayer[tile] = (this->WallOwnerLayer[tile] & ~WO_OWNER_MASK) | (newOwner - 1); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/renderPreviewMapperWithBrush.cpp b/src/OpenSHC/Map/TileMapState/renderPreviewMapperWithBrush.cpp new file mode 100644 index 0000000000..65a975593f --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/renderPreviewMapperWithBrush.cpp @@ -0,0 +1,177 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Game::GameMode; + using OpenSHC::Game::GameMode2; + + // FUNCTION: STRONGHOLDCRUSADER 0x00508A00 + void TileMapState::renderPreviewMapperWithBrush(uint x, uint y, MappersEnum mapper) + { + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE) { + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { + return; + } + + int brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[this->editorActiveBrush]; + int const baseTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + this->buildingPlacementFail = FALSE; + if (mapper == OpenSHC::Commands::M_MAPPER_POND1 || mapper == OpenSHC::Commands::M_MAPPER_POND2_SMALL + || mapper == OpenSHC::Commands::M_MAPPER_POND3_LARGE1 + || mapper == OpenSHC::Commands::M_MAPPER_POND4_LARGE2) { + return; + } + this->buildingPlacementFail = TRUE; + if (mapper == OpenSHC::Commands::M_MAPPER_SIGNPOST) { + return; + } + + ushort gfx; + switch (mapper) { + case OpenSHC::Commands::M_MAPPER_SEA: + case OpenSHC::Commands::M_MAPPER_SHALLOWS: + case OpenSHC::Commands::M_MAPPER_RIVER: + case OpenSHC::Commands::M_MAPPER_MARSH: + case OpenSHC::Commands::M_MAPPER_DUGMOAT: + case OpenSHC::Commands::M_MAPPER_MOAT: + gfx = 57; + break; + case OpenSHC::Commands::M_MAPPER_BEACH: + case OpenSHC::Commands::M_MAPPER_FORD: + gfx = 58; + break; + case OpenSHC::Commands::M_MAPPER_ROCKY: + case OpenSHC::Commands::M_MAPPER_STONES: + case OpenSHC::Commands::M_MAPPER_BOULDERS: + case OpenSHC::Commands::M_MAPPER_PEBBLES: + case OpenSHC::Commands::M_MAPPER_IRON: + gfx = 59; + break; + case OpenSHC::Commands::M_MAPPER_UNDUGMOAT: + case OpenSHC::Commands::M_MAPPER_OIL: + gfx = 61; + break; + case OpenSHC::Commands::M_MAPPER_TREE_OLIVE: + case OpenSHC::Commands::M_MAPPER_TREE_DATE: + case OpenSHC::Commands::M_MAPPER_TREE_COCONUT: + case OpenSHC::Commands::M_MAPPER_TREE_CHERRY: + case OpenSHC::Commands::M_MAPPER_SHRUB_NEEDLE_PALM_A: + case OpenSHC::Commands::M_MAPPER_SHRUB_NEEDLE_PALM_B: + case OpenSHC::Commands::M_MAPPER_SHRUB_NEEDLE_PALM_C: + case OpenSHC::Commands::M_MAPPER_SHRUB_NEEDLE_PALM_D: + case OpenSHC::Commands::M_MAPPER_SHRUB_NEEDLE_PALM_E: + case OpenSHC::Commands::M_MAPPER_SHRUB_PYGMY_A: + case OpenSHC::Commands::M_MAPPER_SHRUB_PYGMY_B: + case OpenSHC::Commands::M_MAPPER_SHRUB_PYGMY_C: + case OpenSHC::Commands::M_MAPPER_SHRUB_PYGMY_D: + case OpenSHC::Commands::M_MAPPER_SHRUB_PYGMY_E: + case OpenSHC::Commands::M_MAPPER_SHRUB_PIPE_CACTUS: + case OpenSHC::Commands::M_MAPPER_SHRUB_SUCCULENT: + case OpenSHC::Commands::M_MAPPER_SHRUB_CYCAD: + case OpenSHC::Commands::M_MAPPER_SHRUB_PRICKLYPEAR: + case OpenSHC::Commands::M_MAPPER_DEER: + case OpenSHC::Commands::M_MAPPER_LION: + case OpenSHC::Commands::M_MAPPER_RABBIT: + case OpenSHC::Commands::M_MAPPER_CAMEL: + case OpenSHC::Commands::M_MAPPER_CROW_SEAGULL: + case OpenSHC::Commands::M_MAPPER_SEAGULL: + brushSize = 1; + case OpenSHC::Commands::M_MAPPER_RAISE: + case OpenSHC::Commands::M_MAPPER_LOWER: + case OpenSHC::Commands::M_MAPPER_EQUALISE: + case OpenSHC::Commands::M_MAPPER_MOUNTAIN: + case OpenSHC::Commands::M_MAPPER_HILL: + case OpenSHC::Commands::M_MAPPER_DELETE: + gfx = 62; + break; + case OpenSHC::Commands::M_MAPPER_SCRUB: + case OpenSHC::Commands::M_MAPPER_DIRT: + case OpenSHC::Commands::M_MAPPER_DUNES: + gfx = 60; + break; + default: + gfx = 56; + } + + switch (mapper) { + case OpenSHC::Commands::M_MAPPER_UNDUGMOAT: + case OpenSHC::Commands::M_MAPPER_DUGMOAT: + case OpenSHC::Commands::M_MAPPER_MOAT: + case OpenSHC::Commands::M_MAPPER_ANTIMOAT: + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT) { + int enemyRange; + int searchRange; + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + enemyRange = 15; + searchRange = 7; + } else { + enemyRange = 30; + searchRange = 30; + } + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, DAT_PathFindingState::ptr)( + DAT_GameSynchronyState::instance.currentPlayerSlotID, x, y, enemyRange) + != FALSE) { + gfx = 62; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isSignPostWithinDistance, + DAT_PathFindingState::ptr)(x, y, DAT_GameState::instance.mapAndTime.unk_signpostDistance + 5) + != FALSE) { + gfx = 62; + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + int const buildRange + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getCastleBuildRangeForMapSize, this)(); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isOpponentBuildingInRange, + DAT_PathFindingState::ptr)(DAT_GameSynchronyState::instance.currentPlayerSlotID, x, y, + searchRange, -1, -1, buildRange + 5) + != 0) { + gfx = 62; + } + } + } + } + + *(int volatile*)&x = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + { + int brushY; + if (mapper != OpenSHC::Commands::M_MAPPER_DUGMOAT && mapper != OpenSHC::Commands::M_MAPPER_UNDUGMOAT + && mapper != OpenSHC::Commands::M_MAPPER_MOAT && mapper != OpenSHC::Commands::M_MAPPER_ANTIMOAT) { + brushY = y; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, (int*)&x, &brushY, baseTile, y); + this->ConstructionGFXLayer[x] = gfx; + } + } else { + int index = 0; + brushY = y; + for (; index < 9; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + FALSE, index, (int*)&x, &brushY, baseTile, y); + this->ConstructionGFXLayer[x] = gfx; + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/renderWallDragPreview.cpp b/src/OpenSHC/Map/TileMapState/renderWallDragPreview.cpp new file mode 100644 index 0000000000..7d5fbfe6e9 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/renderWallDragPreview.cpp @@ -0,0 +1,188 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F8BD0 + void TileMapState::renderWallDragPreview(int playerID, uint x1, uint y1, uint x2, uint y2, short command) + { + int budget = 0; + if (x1 > MC_MAP_XY_LIMIT_INCLUSIVE || y1 > MC_MAP_XY_LIMIT_INCLUSIVE + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y1 * MC_MAP_XY_LIMIT + x1] == 0) { + return; + } + 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; + } + + this->DAT_WallTileCountCurrentDrag = 0; + int overshoot = 2; + if (command == OpenSHC::Commands::M_MAPPER_STAIR) { + budget = this->maxWallHeightInPath; + if (this->field_0x554920 == 0) { + this->ConstructionGFXLayer[DAT_ViewportRenderState::instance.translationMatrix[y1].addXgetTile + x1] + = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 19; + return; + } + } + + int x = x1; + int y = y1; + int const targetX = x2; + int const targetY = y2; + int upY = y1 - y2; + int leftX = x1 - x2; + int downY = y2 - y1; + int rightX = x2 - x1; + int* translation = &DAT_ViewportRenderState::instance.translationMatrix[y1].addXgetTile; + do { + if (command == OpenSHC::Commands::M_MAPPER_STAIR && budget < 24) { + break; + } + int const tile = *translation + x; + if (command == OpenSHC::Commands::M_MAPPER_STAIR && (this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + break; + } + if (this->DAT_WallTileCountCurrentDrag >= this->constructionTileCount) { + break; + } + this->DAT_WallTileCountCurrentDrag += 1; + + BOOLEnum onCrenel = FALSE; + if (command == OpenSHC::Commands::M_MAPPER_WALL && (this->LogicLayer[tile] & L_CRENEL) != 0) { + onCrenel = TRUE; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0 && this->DamageLayer[tile] == 0 && !onCrenel) { + this->DAT_WallTileCountCurrentDrag -= 1; + } else { + if (onCrenel) { + this->DAT_WallTileCountCurrentDrag -= 1; + } + if (this->illegalBuild != FALSE) { + if (command == OpenSHC::Commands::M_MAPPER_WALL) { + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 19; + } else if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 19; + } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 20; + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR) { + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 19; + } + } else if (command == OpenSHC::Commands::M_MAPPER_WALL) { + this->ConstructionGFXLayer[tile] = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1]; + } else if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 1; + } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 4; + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR) { + int steps = (budget - this->HeightLayer[tile]) / 8 - 1; + if (steps <= 0) { + this->DAT_WallTileCountCurrentDrag -= 1; + } else { + this->ConstructionGFXLayer[tile] = (steps > 10 ? 10 : steps) + + GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_BUILDINGS1] + 8; + } + } + } + + int const stepX = x >= targetX ? leftX : rightX; + int const stepY = y >= targetY ? upY : downY; + if (command == OpenSHC::Commands::M_MAPPER_STAIR) { + if (stepX > stepY) { + if (x >= targetX) { + leftX -= 1; + x -= 1; + rightX += 1; + } else { + leftX += 1; + x += 1; + rightX -= 1; + } + } else if (stepY > 0) { + if (y >= targetY) { + translation -= 3; + y -= 1; + upY -= 1; + downY += 1; + } else { + translation += 3; + y += 1; + upY += 1; + downY -= 1; + } + } else if (x == targetX && y == targetY) { + overshoot -= 1; + } else { + overshoot -= 1; + } + } else { + if (stepX != 0) { + if (x >= targetX) { + leftX -= 1; + x -= 1; + rightX += 1; + } else { + leftX += 1; + x += 1; + rightX -= 1; + } + } + if (stepY != 0) { + if (y >= targetY) { + translation -= 3; + y -= 1; + upY -= 1; + downY += 1; + } else { + translation += 3; + y += 1; + upY += 1; + downY -= 1; + } + } + if (x == targetX && y == targetY) { + overshoot -= 1; + } + } + if (budget > 16 && overshoot == 2) { + budget -= 16; + } + } while (x != targetX || y != targetY || overshoot != 0); + + if (this->illegalBuild != FALSE) { + this->DAT_WallTileCountCurrentDrag = 0; + } + if (this->wallDragButtonUp != 0) { + return; + } + if (command == OpenSHC::Commands::M_MAPPER_WOODWALL) { + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processWallBuildingLoss, + DAT_BuildingsState::ptr)(playerID, 0, this->DAT_WallTileCountCurrentDrag, 1); + return; + } + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::processWallBuildingLoss, + DAT_BuildingsState::ptr)(playerID, this->DAT_WallTileCountCurrentDrag, 0, 1); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/renderWallPlacementPreview.cpp b/src/OpenSHC/Map/TileMapState/renderWallPlacementPreview.cpp new file mode 100644 index 0000000000..8e7df97759 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/renderWallPlacementPreview.cpp @@ -0,0 +1,119 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/DE/SHCDE/eGM.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Rocks/Enums/EditorRockType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.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::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB9E0 + void TileMapState::renderWallPlacementPreview(uint x, uint y, short rockKind) + { + int variationStep = 0; + int base = 0; + int size = 0; + int index = 0; + if (x > MC_MAP_XY_LIMIT_INCLUSIVE || y > MC_MAP_XY_LIMIT_INCLUSIVE + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] == 0) { + return; + } + this->buildingPlacementFail = FALSE; + if (rockKind == 0) { + size = 1; + base = 529; + } else if (rockKind == 1) { + size = 1; + base = 533; + } else if (rockKind == 2) { + size = 1; + base = 537; + } else if (rockKind == 3) { + size = 1; + base = 541; + } else if (rockKind == 4) { + size = 2; + base = 465; + } else if (rockKind == 5) { + size = 2; + base = 481; + } else if (rockKind == 6) { + size = 2; + base = 497; + } else if (rockKind == 7) { + size = 2; + base = 513; + } else if (rockKind == 8) { + size = 3; + base = 321; + } else if (rockKind == 9) { + size = 3; + base = 357; + } else if (rockKind == 10) { + size = 3; + base = 393; + } else if (rockKind == 11) { + size = 3; + base = 429; + } else if (rockKind == 12) { + base = 65; + size = 4; + } else if (rockKind == 13) { + base = 129; + size = 4; + } else if (rockKind == 14) { + base = 193; + size = 4; + } else if (rockKind == 15) { + base = 257; + size = 4; + } + + int rotation = this->rockOrientation + this->mapOrientation; + if (this->editorRockType == OpenSHC::Map::Rocks::Enums::ERT_BIGROCK5) { + rotation = this->mapOrientation; + } + if (rotation >= OpenSHC::Map::Enums::MO_UPPER_LIMIT) { + rotation -= OpenSHC::Map::Enums::MO_UPPER_LIMIT; + } + variationStep = rotation / 2 * size * size; + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, size); + int tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile; + tile += this->buildingX + x; + uint const logic = this->LogicLayer[tile]; + if ((logic & (L_BORDER | L_BORDER_EDGE)) != 0) { + return; + } + if ((logic & L_BUILDING) != 0) { + return; + } + if (this->OrganismLayer[tile] != 0) { + return; + } + index++; + } while (index < this->constructionTileCount); + + index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, size); + this->ConstructionGFXLayer[DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y] + .addXgetTile + + this->buildingX + x] = this->buildingOrientedPartIndex + + GMFirstPictureIndex::instance[OpenSHC::DE::SHCDE::GM_ROCKS] + variationStep + base - 1; + index++; + } while (index < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp index 58a4a87ec9..446241e093 100644 --- a/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp +++ b/src/OpenSHC/Map/TileMapState/resetTileAndClearMoat.cpp @@ -34,20 +34,20 @@ namespace Map { int treeID = this->OrganismLayer[tile]; if (treeID < countof(DAT_LandscapeState::instance.trees)) { switch (DAT_LandscapeState::instance.trees[treeID].treeType) { - 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: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_A: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_B: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_C: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_D: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_E: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_A: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_B: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_C: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_D: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_E: + case OpenSHC::Map::Trees::TT_SHRUB_PIPE_CACTUS: + case OpenSHC::Map::Trees::TT_SHRUB_SUCCULENT: + case OpenSHC::Map::Trees::TT_SHRUB_CYCAD: + case OpenSHC::Map::Trees::TT_SHRUB_PRICKLYPEAR: DAT_LandscapeState::instance.trees[treeID].state = 3; } } diff --git a/src/OpenSHC/Map/TileMapState/returnSomeHeight.cpp b/src/OpenSHC/Map/TileMapState/returnSomeHeight.cpp new file mode 100644 index 0000000000..297b00f9d0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/returnSomeHeight.cpp @@ -0,0 +1,81 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Enums/OrganismLayerConstants.hpp" +#include "OpenSHC/Map/Rocks/Enums/RockType.hpp" + +#include "OpenSHC/Globals/DAT_BuildingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::OLC_ROCK_ID_OFFSET; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::Rocks::Enums::RT_3X3_A; + using OpenSHC::Map::Rocks::Enums::RT_4X4_A; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FF990 + uint TileMapState::returnSomeHeight(int tile, int ignoreHuntersHut) + { + uint const logic = this->LogicLayer[tile]; + int extraHeight = 0; + if ((logic & L_KEEP_NON_MANOR_HOUSE) != 0) { + extraHeight + = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(this->BuildingLayer[tile]); + } else if ((logic & L_BUILDING) != 0) { + int const buildingID = this->BuildingLayer[tile]; + int const type = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + switch (type) { + case OpenSHC::Map::Buildings::BT_GATEHOUSELARGE: + case OpenSHC::Map::Buildings::BT_GATEHOUSESMALL: + case OpenSHC::Map::Buildings::BT_TOWER: + case OpenSHC::Map::Buildings::BT_TOWER1: + case OpenSHC::Map::Buildings::BT_TOWER2: + case OpenSHC::Map::Buildings::BT_TOWER3: + case OpenSHC::Map::Buildings::BT_TOWER4: + case OpenSHC::Map::Buildings::BT_TOWER5: + extraHeight + = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID) + + 10; + break; + case OpenSHC::Map::Buildings::BT_HUNTERSHUT: + if (ignoreHuntersHut != 0) { + extraHeight = 0; + break; + } + default: + extraHeight = DAT_BuildingDefinedData::instance.BuildingHeights[type]; + break; + case OpenSHC::Map::Buildings::BT_MANORHOUSE: + case OpenSHC::Map::Buildings::BT_STONEKEEP: + case OpenSHC::Map::Buildings::BT_STRONGHOLD: + case OpenSHC::Map::Buildings::BT_KEEPFOUR: + case OpenSHC::Map::Buildings::BT_KEEPFIVE: + extraHeight + = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID, + DAT_BuildingsState::ptr)(buildingID); + break; + } + } else if ((logic & L_ROCKY) != 0 && (logic & L_WALL_OR_GATEHOUSE) == 0) { + int organism = this->OrganismLayer[tile]; + if (organism >= OLC_ROCK_ID_OFFSET) { + organism -= OLC_ROCK_ID_OFFSET; + if (DAT_LandscapeState::instance.rocks[organism].type >= RT_4X4_A) { + extraHeight = 70; + } else if (DAT_LandscapeState::instance.rocks[organism].type >= RT_3X3_A) { + extraHeight = 50; + } + } + } + return this->HeightLayer[tile] + extraHeight; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setBitFlagBasedOnWallTowerGatehouseOrKeep.cpp b/src/OpenSHC/Map/TileMapState/setBitFlagBasedOnWallTowerGatehouseOrKeep.cpp new file mode 100644 index 0000000000..f9ca1bb66c --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setBitFlagBasedOnWallTowerGatehouseOrKeep.cpp @@ -0,0 +1,27 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Map/TileMapState/NeighbourFlagsGlobalAsm.hpp" + +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FF870 + uint TileMapState::setBitFlagBasedOnWallTowerGatehouseOrKeep(int x, int y) + { + this->DAT_SomeY = y; + this->DAT_SomeTile = MACRO_CALL_MEMBER( + OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, &DAT_ViewportRenderState::instance)(x, y); + + MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_8(1, L_WALL_OR_GATEHOUSE OR L_KEEP_NON_MANOR_HOUSE) + + return this->bitFlag; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setConstructionGFXLayerBasedOnPlacementChecks.cpp b/src/OpenSHC/Map/TileMapState/setConstructionGFXLayerBasedOnPlacementChecks.cpp new file mode 100644 index 0000000000..b9f814aad8 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setConstructionGFXLayerBasedOnPlacementChecks.cpp @@ -0,0 +1,780 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Commands/MappersEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingPlacementFailState.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Buildings::Enums::BPFS_NONE; + using OpenSHC::Map::Buildings::Enums::BPFS_OFF_MAP; + + using OpenSHC::Map::Enums::CD_EAST; + using OpenSHC::Map::Enums::CD_NORTH; + using OpenSHC::Map::Enums::CD_SOUTH; + using OpenSHC::Map::Enums::CD_UNSPECIFIED; + using OpenSHC::Map::Enums::CD_UPPER_LIMIT; + using OpenSHC::Map::Enums::CD_WEST; + using OpenSHC::Map::Enums::MO_EAST; + using OpenSHC::Map::Enums::MO_UPPER_LIMIT; + using OpenSHC::Map::Enums::MO_WEST; + + 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::MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + + // FUNCTION: STRONGHOLDCRUSADER 0x00504F10 + void TileMapState::setConstructionGFXLayerBasedOnPlacementChecks(int x, int y, MappersEnumShort command, int size) + { + int const skipPlacementFailChecks = this->skipPlacementFailChecks; + int keepSpriteVariant = 0; + int i = 0; + int const originX = x; + int const originY = y; + this->skipPlacementFailChecks = 0; + if (skipPlacementFailChecks != 0) { + BuildingType const buildingType = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)((MappersEnum)command); + this->buildingSpriteSheetID_1 + = DAT_BuildingDefinedData::instance.Building_SpriteSheet_ID_Array_1[buildingType].intValue; + this->buildingSpriteID1 = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getSpriteID, + DAT_BuildingsState::ptr)((MappersEnum)command); + this->buildingSpriteID2 = MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getSpriteID2, + DAT_BuildingsState::ptr)((MappersEnum)command); + } else { + if (this->buildingPlacementFail == BPFS_OFF_MAP) { + return; + } + if (this->buildingPlacementFail != BPFS_NONE) { + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(i, size); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + originY].addXgetTile + + this->buildingX + originX; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + i++; + } while (i < this->constructionTileCount); + if (command == OpenSHC::Commands::M_MAPPER_KEEP1 || command == OpenSHC::Commands::M_MAPPER_KEEP2 + || command == OpenSHC::Commands::M_MAPPER_KEEP3) { + int const keepIndex = command - OpenSHC::Commands::M_MAPPER_KEEP1; + for (int part = 0; part != countof(DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0]); + part++) { + XYPair const& offset = DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][part]; + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[offset.y + originY].addXgetTile + + offset.x + originX; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + } + x = originX + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[keepIndex][0].xOffset; + y = originY + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[keepIndex][0].yOffset; + i = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(i, 7); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + i++; + } while (i < this->constructionTileCount); + x = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[keepIndex][0].xOffset + originX; + y = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[keepIndex][0].yOffset + originY; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + j++; + } while (j < this->constructionTileCount); + } + if (command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1A + || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1B + || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1C + || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1D) { + MappersEnum const gateCommand = (MappersEnum)command; + int const tower1X = DAT_TerrainDefinedData::instance + .gateTowerChecks[gateCommand - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A] + .x1 + + originX; + int const tower1Y = DAT_TerrainDefinedData::instance + .gateTowerChecks[gateCommand - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A] + .y1 + + originY; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 3); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + tower1Y].addXgetTile + + this->buildingX + tower1X; + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, + this)(tile, DAT_GameSynchronyState::instance.currentPlayerSlotID, gateCommand, 0) + ? 55 + : 62; + j++; + } while (j < this->constructionTileCount); + int const tower2X = DAT_TerrainDefinedData::instance + .gateTowerChecks[gateCommand - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A] + .x2 + + originX; + int const tower2Y = DAT_TerrainDefinedData::instance + .gateTowerChecks[gateCommand - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A] + .y2 + + originY; + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 3); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + tower2Y].addXgetTile + + this->buildingX + tower2X; + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, + this)(tile, DAT_GameSynchronyState::instance.currentPlayerSlotID, gateCommand, 0) + ? 55 + : 62; + j++; + } while (j < this->constructionTileCount); + for (int j = 0; j != countof(DAT_TerrainDefinedData::instance.gateHouseTiles[0]); j++) { + int const tile = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance + .gateHouseTiles[gateCommand + - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A][j] + .y + + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance + .gateHouseTiles[gateCommand - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A][j] + .x + + originX; + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, + this)(tile, DAT_GameSynchronyState::instance.currentPlayerSlotID, gateCommand, 0) + ? 55 + : 62; + } + } else if (command == OpenSHC::Commands::M_MAPPER_BARRACKS_EURO + || command == OpenSHC::Commands::M_MAPPER_BARRACKS_ARAB) { + int const rightX = originX + 5; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + originY].addXgetTile + + this->buildingX + rightX; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + j++; + } while (j < this->constructionTileCount); + y = originY + 5; + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + originX; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + j++; + } while (j < this->constructionTileCount); + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + rightX; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + j++; + } while (j < this->constructionTileCount); + } else if (command == OpenSHC::Commands::M_MAPPER_ENGINEERS_GUILD + || command == OpenSHC::Commands::M_MAPPER_TUNNELERS_GUILD) { + y = originY + 5; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + originX; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + j++; + } while (j < this->constructionTileCount); + } else if (command == OpenSHC::Commands::M_MAPPER_OIL_SMELTER) { + y = originY + 4; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 4); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + originX; + if ((this->LogicLayer[tile] & (L_KEEP_NON_MANOR_HOUSE | L_BUILDING | L_WALL_OR_GATEHOUSE)) + == 0) { + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER( + OpenSHC::Map::TileMapState_Func::isBuildingPlacementAllowedAtTile, this)(tile, + DAT_GameSynchronyState::instance.currentPlayerSlotID, (MappersEnum)command, FALSE) + ? 55 + : 62; + } + j++; + } while (j < this->constructionTileCount); + } + return; + } + } + if (command == OpenSHC::Commands::M_MAPPER_WHEATFARM) { + size = 3; + } else if (command == OpenSHC::Commands::M_MAPPER_HOPSFARM) { + size = 3; + } else if (command == OpenSHC::Commands::M_MAPPER_APPLEFARM) { + size = 3; + } else if (command == OpenSHC::Commands::M_MAPPER_CATTLEFARM) { + size = 3; + } else if (command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1A + || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1C || command == OpenSHC::Commands::M_MAPPER_GATE_STONE1A + || command == OpenSHC::Commands::M_MAPPER_GATE_STONE2A) { + this->gateOrientationVariant = 81; + } else if (command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1B + || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1D || command == OpenSHC::Commands::M_MAPPER_GATE_STONE1B + || command == OpenSHC::Commands::M_MAPPER_GATE_STONE2B) { + this->gateOrientationVariant = 80; + } + MappersEnum const buildingCommand = (MappersEnum)command; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(i, size); + int rotation = this->uiBuildingRotation; + if (rotation != CD_UNSPECIFIED && rotation != CD_UPPER_LIMIT) { + rotation -= this->mapOrientation; + if (rotation < 0) { + rotation += CD_UPPER_LIMIT; + } + } + int sprite; + if (this->mapOrientation == MO_EAST || this->mapOrientation == MO_WEST) { + if (this->gateOrientationVariant == 81) { + sprite = this->buildingSpriteID1; + } else { + sprite = this->buildingSpriteID2; + } + } else if (this->gateOrientationVariant == 81) { + sprite = this->buildingSpriteID2; + } else { + sprite = this->buildingSpriteID1; + } + if (command == OpenSHC::Commands::M_MAPPER_DRAWBRIDGE && rotation != CD_NORTH) { + if (rotation == CD_EAST) { + rotation = 3; + } else if (rotation == CD_SOUTH) { + rotation = 2; + } else if (rotation == CD_WEST) { + rotation = 1; + } + } + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + originY].addXgetTile + + this->buildingX + originX; + if (MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(buildingCommand) + == OpenSHC::Map::Buildings::BT_UNKNOWN1) { + sprite += DAT_BuildingDefinedData::instance + .UnknownVariations[buildingCommand - OpenSHC::Commands::M_MAPPER_UNKNOWN_248]; + } else if (MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::convertCommandBuildingTypeToBuildingType, + DAT_BuildingsState::ptr)(buildingCommand) + == OpenSHC::Map::Buildings::BT_HOVEL) { + sprite = DAT_BuildingDefinedData::instance.SomeSpriteArray1[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .hovelCountUpToEight]; + } + if (this->uiBuildingRotation != CD_UNSPECIFIED) { + this->ConstructionGFXLayer[tile] = (rotation * size * size) + + GMFirstPictureIndex::instance[this->buildingSpriteSheetID_1] + sprite + + this->buildingOrientedPartIndex - 1; + } else { + this->ConstructionGFXLayer[tile] = GMFirstPictureIndex::instance[this->buildingSpriteSheetID_1] + sprite + + this->buildingOrientedPartIndex - 1; + } + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + i++; + } while (i < this->constructionTileCount); + if (command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1A || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1B + || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1C + || command == OpenSHC::Commands::M_MAPPER_GATE_WOOD1D) { + int const gateIndex = buildingCommand - OpenSHC::Commands::M_MAPPER_GATE_WOOD1A; + int const tower1X = DAT_TerrainDefinedData::instance.gateTowerPlacements[gateIndex].x1; + int const tower1Y = DAT_TerrainDefinedData::instance.gateTowerPlacements[gateIndex].y1; + int const tower1Rotation = DAT_TerrainDefinedData::instance.gateTowerPlacements[gateIndex].rotationIndex1; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 2); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[tower1Y + originY + this->buildingY] + .addXgetTile + + this->buildingX + tower1X + originX; + this->ConstructionGFXLayer[tile] = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[52]; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + for (j = 0; j < countof(DAT_TerrainDefinedData::instance.gateTowerTileOffsets[0]); j++) { + XYPair const& offset = DAT_TerrainDefinedData::instance.gateTowerTileOffsets[tower1Rotation][j]; + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[offset.y + tower1Y + originY].addXgetTile + + offset.x + tower1X + originX; + if (j <= 0) { + this->ConstructionGFXLayer[tile] = GMFirstPictureIndex::instance[52] + j + 1550; + } else { + int towerRotation + = DAT_TerrainDefinedData::instance.ConstructionSpriteRotationTable[tower1Rotation][j - 1] + - this->mapOrientation; + if (towerRotation < 0) { + towerRotation += MO_UPPER_LIMIT; + } + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[52] + (towerRotation / 2) * 4 + j + 1550; + } + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + } + int const tower2X = DAT_TerrainDefinedData::instance.gateTowerPlacements[gateIndex].x2; + int const tower2Y = DAT_TerrainDefinedData::instance.gateTowerPlacements[gateIndex].y2; + int const tower2Rotation = DAT_TerrainDefinedData::instance.gateTowerPlacements[gateIndex].rotationIndex2; + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 2); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[tower2Y + originY + this->buildingY] + .addXgetTile + + this->buildingX + tower2X + originX; + this->ConstructionGFXLayer[tile] = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[52]; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + for (j = 0; j < countof(DAT_TerrainDefinedData::instance.gateTowerTileOffsets[0]); j++) { + XYPair const& offset = DAT_TerrainDefinedData::instance.gateTowerTileOffsets[tower2Rotation][j]; + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[offset.y + tower2Y + originY].addXgetTile + + offset.x + tower2X + originX; + if (j <= 0) { + this->ConstructionGFXLayer[tile] = GMFirstPictureIndex::instance[52] + j + 1550; + } else { + int towerRotation + = DAT_TerrainDefinedData::instance.ConstructionSpriteRotationTable[tower2Rotation][j - 1] + - this->mapOrientation; + if (towerRotation < 0) { + towerRotation += MO_UPPER_LIMIT; + } + this->ConstructionGFXLayer[tile] + = GMFirstPictureIndex::instance[52] + (towerRotation / 2) * 4 + j + 1550; + } + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + } + for (int j = 0; j != countof(DAT_TerrainDefinedData::instance.gateHouseTiles[0]); j++) { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.gateHouseTiles[gateIndex][j].y + originY] + .addXgetTile + + originX + DAT_TerrainDefinedData::instance.gateHouseTiles[gateIndex][j].x; + this->ConstructionGFXLayer[tile] + = (this->RandomLayer[tile] & 3) + GMFirstPictureIndex::instance[6] + 312; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + } + } else if (command == OpenSHC::Commands::M_MAPPER_WHEATFARM) { + int j = 0; + do { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix + [DAT_TerrainDefinedData::instance + .WheatFarmTiles[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .unkWheatFarmOrientation][j] + .y + + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance + .WheatFarmTiles[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .unkWheatFarmOrientation][j] + .x + + originX; + this->ConstructionGFXLayer[tile] = (this->RandomLayer[tile] & 3) + GMFirstPictureIndex::instance[14]; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < countof(DAT_TerrainDefinedData::instance.WheatFarmTiles[0])); + } else if (command == OpenSHC::Commands::M_MAPPER_HOPSFARM) { + int j = 0; + do { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix + [DAT_TerrainDefinedData::instance + .HopFarmProperty1[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .unkHopFarmVariation][j] + .y + + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance + .HopFarmProperty1[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .unkHopFarmVariation][j] + .x + + originX; + this->ConstructionGFXLayer[tile] + = (this->RandomLayer[tile] & 1) * 9 + 37 + GMFirstPictureIndex::instance[14]; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < countof(DAT_TerrainDefinedData::instance.HopFarmProperty1[0])); + } else if (command == OpenSHC::Commands::M_MAPPER_CATTLEFARM) { + for (int j = 0; j < 23; j++) { + int const tile + = DAT_ViewportRenderState::instance + .translationMatrix + [DAT_TerrainDefinedData::instance + .field_0xf5c[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .dairyFarmVariationMod4][j + 4] + .offset.y + + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance + .field_0xf5c[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .dairyFarmVariationMod4][j + 4] + .offset.x + + originX; + this->ConstructionGFXLayer[tile] + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getRubbleGraphicStageForDamageLevel, this)( + DAT_TerrainDefinedData::instance + .field_0xf5c[DAT_GameState::instance + .playerDataArray[DAT_GameSynchronyState::instance.currentPlayerSlotID] + .dairyFarmVariationMod4][j + 4] + .property) + + 55 + GMFirstPictureIndex::instance[14]; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + } + } else if (command == OpenSHC::Commands::M_MAPPER_APPLEFARM) { + int j = 0; + do { + XYPair const& offset = DAT_TerrainDefinedData::instance.AppleFarmOffsets[j]; + int const tile = DAT_ViewportRenderState::instance.translationMatrix[offset.y + originY].addXgetTile + + offset.x + originX; + this->ConstructionGFXLayer[tile] = GMFirstPictureIndex::instance[14] + 61; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < countof(DAT_TerrainDefinedData::instance.AppleFarmOffsets)); + } else if (command == OpenSHC::Commands::M_MAPPER_BARRACKS_EURO + || command == OpenSHC::Commands::M_MAPPER_BARRACKS_ARAB) { + x = originX + 5; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + originY].addXgetTile + + this->buildingX + x; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 72; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + y = originY + 5; + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + originX; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 122; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 97; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + } else if (command == OpenSHC::Commands::M_MAPPER_ENGINEERS_GUILD) { + y = originY + 5; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + originX; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 147; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + } else if (command == OpenSHC::Commands::M_MAPPER_TUNNELERS_GUILD) { + y = originY + 5; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + originX; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 172; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + } else if (command == OpenSHC::Commands::M_MAPPER_OIL_SMELTER) { + y = originY + 4; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 4); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + originX; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 296; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + } else if (command == OpenSHC::Commands::M_MAPPER_KEEP1) { + if (this->mapOrientation == MO_EAST) { + keepSpriteVariant = 1; + } + int const tile1 + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0][0].y + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0][0].x + originX; + this->ConstructionGFXLayer[tile1] = GMFirstPictureIndex::instance[52] + keepSpriteVariant + 1315; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile1] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + int const tile2 + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0][1].y + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0][1].x + originX; + this->ConstructionGFXLayer[tile2] = GMFirstPictureIndex::instance[52] + keepSpriteVariant + 1326; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile2] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + int const tile3 + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0][2].y + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[0][0][2].x + originX; + this->ConstructionGFXLayer[tile3] = GMFirstPictureIndex::instance[52] + keepSpriteVariant + 1319; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile3] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + int const outbuildingX + = originX + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[0][0].xOffset; + int const outbuildingY + = originY + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[0][0].yOffset; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 7); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + outbuildingY].addXgetTile + + this->buildingX + outbuildingX; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 23; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + int const outbuilding2X + = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[0][0].xOffset + originX; + int const outbuilding2Y + = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[0][0].yOffset + originY; + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + outbuilding2Y].addXgetTile + + this->buildingX + outbuilding2X; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[7] + 25; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + } else if (command == OpenSHC::Commands::M_MAPPER_KEEP2 || command == OpenSHC::Commands::M_MAPPER_KEEP3) { + if (this->mapOrientation == MO_EAST) { + keepSpriteVariant = 1; + } + int const keepIndex = buildingCommand - OpenSHC::Commands::M_MAPPER_KEEP1; + int const tile1 + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][0].y + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][0].x + originX; + this->ConstructionGFXLayer[tile1] = GMFirstPictureIndex::instance[52] + keepSpriteVariant + 1313; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile1] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + int const tile2 + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][1].y + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][1].x + originX; + this->ConstructionGFXLayer[tile2] = GMFirstPictureIndex::instance[52] + keepSpriteVariant + 1321; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile2] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + int const tile3 + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][2].y + originY] + .addXgetTile + + DAT_TerrainDefinedData::instance.keepDoorOffsets[keepIndex][0][2].x + originX; + this->ConstructionGFXLayer[tile3] = GMFirstPictureIndex::instance[52] + keepSpriteVariant + 1317; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile3] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + int const outbuildingX + = originX + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[keepIndex][0].xOffset; + int const outbuildingY + = originY + DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x384[keepIndex][0].yOffset; + int j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 7); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + outbuildingY].addXgetTile + + this->buildingX + outbuildingX; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[6] + 23; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + int const outbuilding2X + = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[keepIndex][0].xOffset + originX; + int const outbuilding2Y + = DAT_TerrainDefinedData::instance.keepOutbuildingOffsets_0x3e4[keepIndex][0].yOffset + originY; + j = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(j, 5); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + outbuilding2Y].addXgetTile + + this->buildingX + outbuilding2X; + this->ConstructionGFXLayer[tile] + = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[7] + 25; + if (skipPlacementFailChecks != 0) { + this->MiscDisplayLayer[tile] |= MD_PREVIEW_IGNORES_PLACEMENT_FAIL; + } + j++; + } while (j < this->constructionTileCount); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setLand.cpp b/src/OpenSHC/Map/TileMapState/setLand.cpp new file mode 100644 index 0000000000..b742a932c0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setLand.cpp @@ -0,0 +1,95 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.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::L2_PLATEAU_HIGH; + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_MEDIUM; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_CLIMBABLE; + using OpenSHC::Map::LogicHelpers::L_DEFAULT_EARTH_OR_TEXTURE; + 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::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + 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_ROCKY; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + 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_DESTROY_PENDING; + using OpenSHC::Map::LogicHelpers::MD_GATEHOUSE_RAISED; + using OpenSHC::Map::LogicHelpers::MD_SEA_EDGES; + + // FUNCTION: STRONGHOLDCRUSADER 0x00502390 + void TileMapState::setLand(int tile, int y, uint brushType) + { + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[brushType]; + int const baseTile = tile; + int const baseY = y; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, baseY); + int const brushTile = tile; + if ((this->LogicLayer[brushTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + continue; + } + if ((this->LogicLayer[brushTile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[brushTile] != 0) { + continue; + } + if ((this->LogicLayer[brushTile] & L_TREE) != 0) { + continue; + } + if ((this->LogicLayer[brushTile] & L_ROCKY) != 0 && this->OrganismLayer[brushTile] != 0) { + continue; + } + if (this->DefaultHeightLayer[brushTile] < 8) { + this->DefaultHeightLayer[brushTile] = 8; + } + this->HeightLayer[brushTile] = this->DefaultHeightLayer[brushTile]; + this->MiscDisplayLayer[brushTile] &= ~MD_GATEHOUSE_RAISED; + if ((this->LogicLayer[brushTile] & (L_MOAT | L_MOAT_DUG_OR_PLANNED)) != 0) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(brushTile + - DAT_ViewportRenderState::instance + .translationMatrix[DAT_ViewportRenderState::instance + .tileTranslationMatrix_YComponent[brushTile]] + .addXgetTile, + DAT_ViewportRenderState::instance.tileTranslationMatrix_YComponent[brushTile]); + this->LogicLayer[brushTile] &= ~(L_MOAT | L_MOAT_DUG_OR_PLANNED); + } + this->LogicLayer[brushTile] + &= (L_STOCKPILEUnk | L_PLAIN1_AND_FARM | L_BORDER | L_BORDER_EDGE | L_BUILDING | L_MOAT_DUG_OR_PLANNED + | L_DEFAULT_EARTH_OR_TEXTURE | L_UNKNOWN_WALL_RELATED | L_CLIMBABLE | L_FARM_FIELD_WHEAT + | L_FARM_FIELD_HOP | L_FARM_FIELD_APPLE | L_FARM_FIELD_DAIRY | L_KEEP_NON_MANOR_HOUSE | L_MOAT); + this->MiscDisplayLayer[brushTile] &= ~(MD_SEA_EDGES | MD_DESTROY_PENDING); + this->Logic2Layer[brushTile] = 0; + if (DAT_TileMapState::instance.HeightLayer[brushTile] == 80) { + this->Logic2Layer[brushTile] = L2_PLATEAU_MEDIUM; + } else if (DAT_TileMapState::instance.HeightLayer[brushTile] == 130) { + this->Logic2Layer[brushTile] = L2_PLATEAU_HIGH; + } + this->WallOwnerLayer[brushTile] = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(y, brushTile); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setMiscDisplayLayer.cpp b/src/OpenSHC/Map/TileMapState/setMiscDisplayLayer.cpp new file mode 100644 index 0000000000..d35af741bf --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setMiscDisplayLayer.cpp @@ -0,0 +1,123 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::LogicHelpers::MD_BUILDING_MAIN_TILE; + using OpenSHC::Map::LogicHelpers::MD_BUILDING_SECOND_TILEUnk; + using OpenSHC::Map::LogicHelpers::MD_BUILDING_TILES; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB0C0 + void TileMapState::setMiscDisplayLayer(int buildingID) + { + int const rotation = this->mapOrientation / 2; + if (DAT_BuildingsState::instance.buildings[buildingID].unknownStockpileOrSignpostRelated == 0) { + return; + } + + int const x = DAT_BuildingsState::instance.buildings[buildingID].x; + int const y = DAT_BuildingsState::instance.buildings[buildingID].y; + int const size = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; + OpenSHC::Map::Buildings::BuildingTypeShort const type + = DAT_BuildingsState::instance.buildings[buildingID].buildingType; + int const typeInt = type; + int workerTile = DAT_TerrainDefinedData::instance.orientationRelativeBuildingTileOffset1[size][rotation]; + int displayTile = DAT_TerrainDefinedData::instance.orientationRelativeBuildingTileOffset2[size][rotation]; + int extraTile = -1; + switch (typeInt) { + case OpenSHC::Map::Buildings::BT_IRONMINE: + case OpenSHC::Map::Buildings::BT_PITCHRIG: + case OpenSHC::Map::Buildings::BT_HUNTERSHUT: + case OpenSHC::Map::Buildings::BT_BLACKSMITH: + case OpenSHC::Map::Buildings::BT_BREWERY: + case OpenSHC::Map::Buildings::BT_OILSMELTER: + case OpenSHC::Map::Buildings::BT_STABLES: + case OpenSHC::Map::Buildings::BT_MANORHOUSE: + case OpenSHC::Map::Buildings::BT_KEEPFOUR: + case OpenSHC::Map::Buildings::BT_KEEPFIVE: + case OpenSHC::Map::Buildings::BT_TUNNEL: + case OpenSHC::Map::Buildings::BT_FIREBALLISTA: + case OpenSHC::Map::Buildings::BT_MAYPOLE: + case OpenSHC::Map::Buildings::BT_CATAPULT: + case OpenSHC::Map::Buildings::BT_TREBUCHET: + case OpenSHC::Map::Buildings::BT_BATTERINGRAM: + case OpenSHC::Map::Buildings::BT_SIEGETOWER: + case OpenSHC::Map::Buildings::BT_SHIELD: + case OpenSHC::Map::Buildings::BT_UNKNOWN4: + displayTile = workerTile; + workerTile = DAT_TerrainDefinedData::instance.orientationRelativeBuildingTileOffset2[size][rotation]; + break; + case OpenSHC::Map::Buildings::BT_DRAWBRIDGE: + workerTile = DAT_TerrainDefinedData::instance.orientationRelativeBuildingTileOffset1[size][rotation]; + switch (rotation) { + case 0: + displayTile = 19; + extraTile = 6; + break; + case 1: + displayTile = 21; + extraTile = 8; + break; + case 2: + displayTile = 5; + extraTile = 18; + break; + case 3: + displayTile = 3; + extraTile = 16; + } + break; + case OpenSHC::Map::Buildings::BT_GALLOWS: + case OpenSHC::Map::Buildings::BT_GIBBET: + workerTile = -1; + } + + if (size <= 2 && type != OpenSHC::Map::Buildings::BT_GIBBET && type != OpenSHC::Map::Buildings::BT_GALLOWS) { + int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + this->MiscDisplayLayer[tile] |= MD_BUILDING_MAIN_TILE; + return; + } + + int clearIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(clearIndex, size); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + this->MiscDisplayLayer[tile] &= ~MD_BUILDING_TILES; + clearIndex++; + } while (clearIndex < this->constructionTileCount); + + int index = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)(index, size); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + x + + this->buildingX; + if (typeInt == OpenSHC::Map::Buildings::BT_GRANARY) { + this->MiscDisplayLayer[tile] |= MD_BUILDING_SECOND_TILEUnk; + } else if (typeInt == OpenSHC::Map::Buildings::BT_ARMORY) { + this->MiscDisplayLayer[tile] |= MD_BUILDING_SECOND_TILEUnk; + } else if (index == workerTile) { + this->MiscDisplayLayer[tile] |= MD_BUILDING_SECOND_TILEUnk; + DAT_BuildingsState::instance.buildings[buildingID].secondTileUnk = tile; + } + if (index == displayTile) { + this->MiscDisplayLayer[tile] |= MD_BUILDING_MAIN_TILE; + DAT_BuildingsState::instance.buildings[buildingID].miscDisplayLayerTile = tile; + } + if (index == extraTile) { + this->MiscDisplayLayer[tile] |= MD_BUILDING_TILES; + DAT_BuildingsState::instance.buildings[buildingID].miscDisplayLayerTile = tile; + } + index++; + } while (index < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setTerrain.cpp b/src/OpenSHC/Map/TileMapState/setTerrain.cpp new file mode 100644 index 0000000000..ddd8813eb7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setTerrain.cpp @@ -0,0 +1,545 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/TileMapState/NeighbourFlagsGlobalAsm.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Game::GameMode2; + using OpenSHC::Map::LogicHelpers::L2_BEACH; + using OpenSHC::Map::LogicHelpers::L2_EARTH_AND_STONES; + using OpenSHC::Map::LogicHelpers::L2_MOAT_UNDUG; + using OpenSHC::Map::LogicHelpers::L2_NONE; + using OpenSHC::Map::LogicHelpers::L2_OASIS_GRASS; + using OpenSHC::Map::LogicHelpers::L2_SCRUB; + using OpenSHC::Map::LogicHelpers::L2_STONES_OR_DRIVEN_SANDUnk; + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_BORDER; + 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_NONE; + using OpenSHC::Map::LogicHelpers::L_OIL; + using OpenSHC::Map::LogicHelpers::L_PEBBLES; + using OpenSHC::Map::LogicHelpers::L_PLAIN1_AND_FARM; + using OpenSHC::Map::LogicHelpers::L_PLAIN2_AND_PITCH; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_UNNAMED_0x40; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_GATEHOUSE_RAISED; + + // FUNCTION: STRONGHOLDCRUSADER 0x00512940 + void TileMapState::setTerrain(int playerID, int tile, uint yParam, uint brushType, Logic1 flags1, Logic2 flags2) + { + uint x; + int numTiles; + uint baseY; + int index; + int moatEnemyDistance; + int moatOpponentRange; + int baseTile; + + numTiles = DAT_TerrainDefinedData::instance.BrushSizeArray[brushType]; + baseTile = tile; + baseY = yParam; + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + moatEnemyDistance = 15; + moatOpponentRange = 7; + } else { + moatEnemyDistance = 30; + moatOpponentRange = 30; + } + + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR && flags1 != L_MOAT + && (flags2 == L2_EARTH_AND_STONES || flags2 == L2_OASIS_GRASS || flags2 == L2_BEACH + || flags2 == L2_STONES_OR_DRIVEN_SANDUnk || flags2 == L2_SCRUB || flags2 == L2_THICK_SCRUB)) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setLand, this)(tile, yParam, brushType); + } + if (flags1 == L_MOAT) { + numTiles = 9; + } + + for (index = 0; index < numTiles; index++) { + if (flags1 == L_MOAT) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 0, index, &tile, (int*)&yParam, baseTile, baseY); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, &tile, (int*)&yParam, baseTile, baseY); + } + if ((this->LogicLayer[tile] & L_BORDER) != 0) { + continue; + } + + if (flags1 == L_SEA) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_PEBBLES; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_MARSH; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= flags1; + this->HeightLayer[tile] = 0; + this->DefaultHeightLayer[tile] = 0; + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + } else if (flags1 == L_RIVER || flags1 == L_FORD) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + if (flags2 != L2_NONE && (this->LogicLayer[tile] & L_RIVER) == 0) { + continue; + } + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + if (flags1 == L_RIVER) { + this->LogicLayer[tile] &= ~L_FORD; + } else { + this->LogicLayer[tile] &= ~L_RIVER; + } + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_PEBBLES; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_MARSH; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + this->LogicLayer[tile] &= ~L_SEA; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + if (flags2 != L2_BEACH) { + this->WallGFXLayer[tile] = this->RandomLayer[tile] & 7; + } + if (flags2 == L2_OASIS_GRASS) { + this->Logic2Layer[tile] = L2_OASIS_GRASS; + } + if (flags2 == L2_BEACH) { + this->Logic2Layer[tile] = L2_BEACH; + this->WallGFXLayer[tile] = (DAT_GameCore::instance.mapTimeInTicks & 8) + + this->WallGFXLayer[tile] * 32 + (this->RandomLayer[tile] & 7) * 1024; + } + this->LogicLayer[tile] |= flags1; + if (this->HeightLayer[tile] >= 8) { + this->HeightLayer[tile] = this->DefaultHeightLayer[tile] - 8; + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + } + } else if (flags1 == L_ROCKY) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_RIVER) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_SEA) != 0) { + this->HeightLayer[tile] = 0; + this->DefaultHeightLayer[tile] = 0; + } else if (this->HeightLayer[tile] < 8) { + this->HeightLayer[tile] = 8; + this->DefaultHeightLayer[tile] = 8; + } + this->LogicLayer[tile] &= ~L_SEA; + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_PEBBLES; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_MARSH; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= flags1; + } else if (flags1 == L_IRON) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_SEA) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_RIVER) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_PEBBLES; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_MARSH; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= flags1; + } else if (flags1 == L_PEBBLES) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_RIVER) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_SEA) != 0) { + this->HeightLayer[tile] = 0; + this->DefaultHeightLayer[tile] = 0; + } else if (this->HeightLayer[tile] < 8) { + this->HeightLayer[tile] = 8; + this->DefaultHeightLayer[tile] = 8; + } + this->LogicLayer[tile] &= ~L_SEA; + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_MARSH; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= flags1; + } else if (flags1 == L_MARSH) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_RIVER) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + this->HeightLayer[tile] = 8; + this->DefaultHeightLayer[tile] = 8; + this->LogicLayer[tile] &= ~L_SEA; + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= flags1; + } else if (flags1 == L_OIL) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_RIVER) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_MARSH) == 0) { + continue; + } + this->LogicLayer[tile] &= ~L_SEA; + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= flags1; + } else if (flags1 == L_MOAT) { + if (this->OrganismLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_SEA) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_RIVER) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_FORD) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_ROCKY) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_BOULDERS) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_IRON) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_MARSH) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_PLAIN1_AND_FARM) != 0) { + continue; + } + x = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::computeTileXOffset, + &DAT_ViewportRenderState::instance)(tile, yParam); + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT + && MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + &DAT_PathFindingState::instance)(playerID, x, yParam, moatEnemyDistance) + != FALSE) { + continue; + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isOpponentBuildingInRange, + &DAT_PathFindingState::instance)(playerID, x, yParam, moatOpponentRange, -1, -1, + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getCastleBuildRangeForMapSize, this)() + + 5) + != 0) { + continue; + } + } + if ((this->LogicLayer[tile] & L_MOAT) != 0 && flags2 != L2_MOAT_UNDUG) { + continue; + } + if (this->HeightLayer[tile] > 12) { + continue; + } + if (flags2 == L2_NONE) { + if ((this->LogicLayer[tile] & L_MOAT_DUG_OR_PLANNED) == 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::createMoatData, this)( + playerID, x, yParam, 0) + != 0) { + this->LogicLayer[tile] |= L_MOAT_DUG_OR_PLANNED; + } + } else if (flags2 == L2_SCRUB) { + if ((this->LogicLayer[tile] & L_MOAT_DUG_OR_PLANNED) != 0) { + this->LogicLayer[tile] &= ~L_MOAT_DUG_OR_PLANNED; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(x, yParam); + } + } else { + this->HeightLayer[tile] = 8; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + if (flags2 == L2_EARTH_AND_STONES) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::createMoatData, this)( + playerID, x, yParam, 1) + != 0) { + this->LogicLayer[tile] &= ~L_MOAT_DUG_OR_PLANNED; + this->LogicLayer[tile] |= L_MOAT; + this->HeightLayer[tile] = 0; + } + } else if (flags2 == L2_MOAT_UNDUG) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::clearMoatDataAtTile, this)(x, yParam); + this->HeightLayer[tile] = 8; + this->LogicLayer[tile] &= ~L_MOAT_DUG_OR_PLANNED; + this->LogicLayer[tile] &= ~L_MOAT; + } + } + } else if (flags2 == L2_EARTH_AND_STONES || flags2 == L2_OASIS_GRASS || flags2 == L2_BEACH + || flags2 == L2_STONES_OR_DRIVEN_SANDUnk || flags2 == L2_SCRUB || flags2 == L2_THICK_SCRUB) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & (L_SEA | L_RIVER | L_FORD | L_MARSH | L_MOAT)) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + if (flags2 == L2_EARTH_AND_STONES) { + if ((this->LogicLayer[tile] & L_IRON) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_BOULDERS) != 0) { + continue; + } + if ((this->Logic2Layer[tile] & L2_BEACH) != 0) { + continue; + } + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(1, L2_BEACH) + if (this->bitFlag != 0) { + continue; + } + } + + this->MiscDisplayLayer[tile] &= ~MD_GATEHOUSE_RAISED; + if (flags2 == L2_STONES_OR_DRIVEN_SANDUnk) { + } else if (flags2 == L2_SCRUB) { + } else if (flags2 == L2_THICK_SCRUB) { + } else if (flags2 == L2_EARTH_AND_STONES) { + } else if (flags2 == L2_OASIS_GRASS) { + } else if (flags2 == L2_BEACH) { + this->HeightLayer[tile] = 0; + this->DefaultHeightLayer[tile] = 0; + } else { + this->HeightLayer[tile] = 8; + this->DefaultHeightLayer[tile] = 8; + } + this->LogicLayer[tile] &= ~L_SEA; + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_BOULDERS; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_MARSH; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + if (flags2 != L2_EARTH_AND_STONES) { + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + } + this->Logic2Layer[tile] = flags2; + } else if (flags1 == L_BOULDERS) { + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_RIVER) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_SEA) != 0) { + this->HeightLayer[tile] = 0; + this->DefaultHeightLayer[tile] = 0; + } else if (this->HeightLayer[tile] < 8) { + this->HeightLayer[tile] = 8; + this->DefaultHeightLayer[tile] = 8; + } + this->LogicLayer[tile] &= ~L_SEA; + this->LogicLayer[tile] &= ~L_UNNAMED_0x40; + this->LogicLayer[tile] &= ~L_RIVER; + this->LogicLayer[tile] &= ~L_FORD; + this->LogicLayer[tile] &= ~L_ROCKY; + this->LogicLayer[tile] &= ~L_PEBBLES; + this->LogicLayer[tile] &= ~L_IRON; + this->LogicLayer[tile] &= ~L_MARSH; + this->LogicLayer[tile] &= ~L_OIL; + this->LogicLayer[tile] &= ~L_MOAT; + this->LogicLayer[tile] &= ~L_PLAIN2_AND_PITCH; + this->Logic2Layer[tile] = 0; + this->LogicLayer[tile] |= flags1; + } else if (flags1 == L_UNNAMED_0x40) { + if ((this->LogicLayer[tile] & L_SEA) == 0) { + continue; + } + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + continue; + } + if (this->BuildingLayer[tile] != 0) { + continue; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + continue; + } + if (this->OrganismLayer[tile] != 0) { + continue; + } + this->LogicLayer[tile] |= flags1; + } + + if (flags1 != L_NONE) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + &DAT_PathFindingState::instance)(yParam, tile); + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setXYBasedOnMoatID.cpp b/src/OpenSHC/Map/TileMapState/setXYBasedOnMoatID.cpp new file mode 100644 index 0000000000..2644614395 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setXYBasedOnMoatID.cpp @@ -0,0 +1,54 @@ +#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 { + + // FUNCTION: STRONGHOLDCRUSADER 0x005003D0 + int TileMapState::setXYBasedOnMoatID(int moatID, int mode, uint x, uint y) + { + bool const isOnMap = x <= MC_MAP_XY_LIMIT_INCLUSIVE && y <= MC_MAP_XY_LIMIT_INCLUSIVE + && DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] != 0; + if (!isOnMap) { + return 0; + } + + int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int const tilePathConnection = this->PathConnectionLayer[tile]; + int const tileHeight = this->HeightLayer[tile]; + if (mode == 1) { + this->ALG_MoatXResult = this->moats[moatID].x; + this->ALG_MoatYResult = this->moats[moatID].y; + return DAT_ViewportRenderState::instance.translationMatrix[this->ALG_MoatYResult].addXgetTile + + this->ALG_MoatXResult; + } + if (mode != 2) { + return 0; + } + + for (int direction = 0; direction < countof(this->directionTranslationMatrix[0]); direction++) { + int const neighbour + = this->directionTranslationMatrix[this->moats[moatID].y][direction] + this->moats[moatID].tile; + if (this->HeightLayer[neighbour] > tileHeight + 16) { + continue; + } + if (this->PathConnectionLayer[neighbour] != tilePathConnection) { + continue; + } + + this->someMoatTile = this->moats[moatID].tile; + this->ALG_MoatXResult = this->moats[moatID].x + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset; + this->ALG_MoatYResult = this->moats[moatID].y + + DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset; + return neighbour; + } + return 0; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setupBuildingSizeIndexMappingForBuildingWithSize.cpp b/src/OpenSHC/Map/TileMapState/setupBuildingSizeIndexMappingForBuildingWithSize.cpp new file mode 100644 index 0000000000..c04c2c99a0 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setupBuildingSizeIndexMappingForBuildingWithSize.cpp @@ -0,0 +1,129 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/IO/LowLevelMemory.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingSizeIndexMapping.hpp" +#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x004F9590 + void TileMapState::setupBuildingSizeIndexMappingForBuildingWithSize(int buildingSize) + { + int const tileCount = buildingSize * buildingSize; + int const maxCoord = buildingSize - 1; + MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)( + sizeof(DAT_BuildingSizeIndexMapping::instance[buildingSize]), 0, + DAT_BuildingSizeIndexMapping::instance + buildingSize); + if (buildingSize <= 1) { + return; + } + + for (int y = 0; y < buildingSize; y++) { + for (int x = 0; x < buildingSize; x++) { + DAT_BuildingSizeIndexMapping::instance[buildingSize][y * buildingSize + x].x = x; + DAT_BuildingSizeIndexMapping::instance[buildingSize][y * buildingSize + x].y = y; + } + } + + int const last = tileCount - 1; + int x = 0; + int y = 0; + int run; + int index = last; + int diagonal; + for (diagonal = 0, run = 1; diagonal < buildingSize * 2 - 1; diagonal++) { + for (int step = 0; step < run; step++) { + DAT_BuildingSizeIndexMapping::instance[buildingSize][y * buildingSize + x].orientedPartIndex[0] = index; + index--; + if (step < run - 1) { + x--; + y++; + } + } + if (diagonal < buildingSize - 1) { + run++; + x = diagonal + 1; + y = 0; + } else { + run--; + x = maxCoord; + y = 1 - maxCoord + diagonal; + } + } + + x = maxCoord; + y = 0; + index = last; + for (diagonal = 0, run = 1; diagonal < buildingSize * 2 - 1; diagonal++) { + for (int step = 0; step < run; step++) { + DAT_BuildingSizeIndexMapping::instance[buildingSize][y * buildingSize + x].orientedPartIndex[1] = index; + index--; + if (step < run - 1) { + x--; + y--; + } + } + if (diagonal < maxCoord) { + run++; + x = maxCoord; + y = diagonal + 1; + } else { + run--; + x = maxCoord + (buildingSize - 2) - diagonal; + y = maxCoord; + } + } + + x = maxCoord; + y = maxCoord; + int secondIndex = last; + for (diagonal = 0, run = 1; diagonal < buildingSize * 2 - 1; diagonal++) { + for (int step = 0; step < run; step++) { + DAT_BuildingSizeIndexMapping::instance[buildingSize][y * buildingSize + x].orientedPartIndex[2] + = secondIndex; + secondIndex--; + if (step < run - 1) { + x++; + y--; + } + } + if (diagonal < maxCoord) { + run++; + x = buildingSize - 2 - diagonal; + y = maxCoord; + } else { + run--; + x = 0; + y = (buildingSize - 2 - diagonal) + maxCoord; + } + } + + x = 0; + y = maxCoord; + secondIndex = last; + for (diagonal = 0, run = 1; diagonal < buildingSize * 2 - 1; diagonal++) { + for (int step = 0; step < run; step++) { + DAT_BuildingSizeIndexMapping::instance[buildingSize][y * buildingSize + x].orientedPartIndex[3] + = secondIndex; + secondIndex--; + if (step < run - 1) { + x++; + y++; + } + } + if (diagonal < maxCoord) { + run++; + x = 0; + y = buildingSize - 2 - diagonal; + } else { + run--; + x = 1 - maxCoord + diagonal; + y = 0; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/setupMovementDirectionTranslationMatrix.cpp b/src/OpenSHC/Map/TileMapState/setupMovementDirectionTranslationMatrix.cpp new file mode 100644 index 0000000000..f13e5a35c5 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/setupMovementDirectionTranslationMatrix.cpp @@ -0,0 +1,74 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::CD_EAST; + using OpenSHC::Map::Enums::CD_NORTH; + using OpenSHC::Map::Enums::CD_NORTHEAST; + using OpenSHC::Map::Enums::CD_NORTHWEST; + using OpenSHC::Map::Enums::CD_SOUTH; + using OpenSHC::Map::Enums::CD_SOUTHEAST; + using OpenSHC::Map::Enums::CD_SOUTHWEST; + using OpenSHC::Map::Enums::CD_UPPER_LIMIT; + using OpenSHC::Map::Enums::CD_WEST; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F6B20 + void TileMapState::setupMovementDirectionTranslationMatrix() + { + int width = 2; + for (int row = 0, offsetIndex = 0; width < MC_MAP_XY_LIMIT; row++, width += 2, offsetIndex += CD_UPPER_LIMIT) { + int* const offsets = this->directionTranslationMatrix[0] + offsetIndex; + offsets[CD_NORTH] = 1 - width; + offsets[CD_NORTHEAST] = 2 - width; + offsets[CD_EAST] = 1; + offsets[CD_SOUTHEAST] = width + 2; + offsets[CD_SOUTH] = width + 1; + offsets[CD_SOUTHWEST] = width; + offsets[CD_WEST] = -1; + offsets[CD_NORTHWEST] = -width; + this->yArray1[row] = width; + } + + int (&upperMiddle)[CD_UPPER_LIMIT] = this->directionTranslationMatrix[MC_MAP_XY_LIMIT / 2 - 1]; + upperMiddle[CD_NORTH] = 1 - width; + upperMiddle[CD_NORTHEAST] = 2 - width; + upperMiddle[CD_EAST] = 1; + upperMiddle[CD_SOUTHEAST] = width + 1; + upperMiddle[CD_SOUTH] = width; + upperMiddle[CD_SOUTHWEST] = width - 1; + upperMiddle[CD_WEST] = -1; + upperMiddle[CD_NORTHWEST] = -width; + this->yArray1[MC_MAP_XY_LIMIT / 2 - 1] = width; + int (&lowerMiddle)[CD_UPPER_LIMIT] = this->directionTranslationMatrix[MC_MAP_XY_LIMIT / 2]; + lowerMiddle[CD_NORTH] = -width; + lowerMiddle[CD_NORTHEAST] = 1 - width; + lowerMiddle[CD_EAST] = 1; + lowerMiddle[CD_SOUTHEAST] = width; + lowerMiddle[CD_SOUTH] = width - 1; + lowerMiddle[CD_SOUTHWEST] = width - 2; + lowerMiddle[CD_WEST] = -1; + lowerMiddle[CD_NORTHWEST] = -1 - width; + this->yArray1[MC_MAP_XY_LIMIT / 2] = width; + + for (int row = MC_MAP_XY_LIMIT / 2 + 1, lowerWidth = width - 2, + offsetIndex = (MC_MAP_XY_LIMIT / 2 + 1) * CD_UPPER_LIMIT; + lowerWidth > 0; row++, lowerWidth -= 2, offsetIndex += CD_UPPER_LIMIT) { + int* const offsets = this->directionTranslationMatrix[0] + offsetIndex; + offsets[CD_NORTH] = -1 - lowerWidth; + offsets[CD_NORTHEAST] = -lowerWidth; + offsets[CD_EAST] = 1; + offsets[CD_SOUTHEAST] = lowerWidth; + offsets[CD_SOUTH] = lowerWidth - 1; + offsets[CD_SOUTHWEST] = lowerWidth - 2; + offsets[CD_WEST] = -1; + offsets[CD_NORTHWEST] = -2 - lowerWidth; + this->yArray1[row] = lowerWidth; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/spawnFloatingNumberAroundTile.cpp b/src/OpenSHC/Map/TileMapState/spawnFloatingNumberAroundTile.cpp new file mode 100644 index 0000000000..ceab6b4758 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/spawnFloatingNumberAroundTile.cpp @@ -0,0 +1,42 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/IO/Graphics/GmID.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_BUILDING; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FB3F0 + void TileMapState::spawnFloatingNumberAroundTile(int x, int y, int type) + { + int const radius = type / 2; + int index = 0; + x -= radius; + y -= radius; + for (int xOffset = DAT_TerrainDefinedData::instance.field_0x2764[radius][index].x; xOffset != -1; + xOffset = DAT_TerrainDefinedData::instance.field_0x2764[radius][index].x) { + int const yOffset = DAT_TerrainDefinedData::instance.field_0x2764[radius][index].y; + int const tile = DAT_ViewportRenderState::instance.translationMatrix[yOffset + y].addXgetTile + xOffset + x; + if ((this->LogicLayer[tile] & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) == 0 + && (index & 1) == 0) { + int const frame + = (DAT_TileMapState::instance.cursorOverlayAnimationFrame + yOffset + xOffset + index + x + y - 1) + % 16; + MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::createFloatingLayerElement, + DAT_ViewportRenderState::ptr)( + OpenSHC::IO::Graphics::GID_FLOATS_NEW, frame + 229, 16, 14, tile, 0x100021); + } + index++; + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/stampBuildingOntoTileMap.cpp b/src/OpenSHC/Map/TileMapState/stampBuildingOntoTileMap.cpp new file mode 100644 index 0000000000..1f6db08c47 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/stampBuildingOntoTileMap.cpp @@ -0,0 +1,41 @@ +#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 { + + using OpenSHC::Map::LogicHelpers::L_BUILDING; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507060 + void TileMapState::stampBuildingOntoTileMap(int playerID, uint x, uint y, BuildingTypeShort buildingType, + short variation, uint buildingSize, int orientation, int averageHeight) + { + int index = 0; + int const buildingID = MACRO_CALL_MEMBER( + OpenSHC::Map::Buildings::BuildingsState_Func::setupBuildingData, DAT_BuildingsState::ptr)( + playerID, x, y, averageHeight, (BuildingType)buildingType, buildingSize, playerID, variation); + this->placedBuildingID = buildingID; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, buildingSize); + int const tile = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + y].addXgetTile + + this->buildingX + x; + if (index < countof(DAT_BuildingsState::instance.buildings[buildingID].tileRefs)) { + DAT_BuildingsState::instance.buildings[buildingID].tileRefs[index] = tile; + } + this->HeightLayer[tile] = averageHeight; + this->LogicLayer[tile] |= L_BUILDING; + this->BuildingLayer[tile] = buildingID; + index++; + this->ChangedLayer[tile] = 2; + } while (index < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::setMiscDisplayLayer, this)(buildingID); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateBuildingGraphicsLayer.cpp b/src/OpenSHC/Map/TileMapState/updateBuildingGraphicsLayer.cpp new file mode 100644 index 0000000000..59c4e06bb2 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateBuildingGraphicsLayer.cpp @@ -0,0 +1,304 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/GMFirstPictureIndex.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::MO_EAST; + using OpenSHC::Map::Enums::MO_NONE; + using OpenSHC::Map::Enums::MO_UPPER_LIMIT; + using OpenSHC::Map::Enums::MO_WEST; + + // FUNCTION: STRONGHOLDCRUSADER 0x00506370 + void TileMapState::updateBuildingGraphicsLayer(int buildingID) + { + int const buildingXPos = DAT_BuildingsState::instance.buildings[buildingID].x; + int const buildingYPos = DAT_BuildingsState::instance.buildings[buildingID].y; + int index = 0; + DAT_BuildingsState::instance.buildings[buildingID].useOffsetGraphics = 0; + if (this->refreshRelatedOne == 0 && DAT_BuildingsState::instance.buildings[buildingID].gfxOffset != 0) { + DAT_BuildingsState::instance.buildings[buildingID].useOffsetGraphics = 1; + } + int const stored = DAT_BuildingsState::instance.buildings[buildingID].currentNumberOfResource + - DAT_BuildingsState::instance.buildings[buildingID].someResourceNumber; + + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + index, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int const tile + = DAT_ViewportRenderState::instance.translationMatrix[this->buildingY + buildingYPos].addXgetTile + + buildingXPos + this->buildingX; + if (this->disableElevationRendering != 0) { + this->GfxLayer[tile] + = DAT_TerrainDefinedData::instance + .BrushSizeArray[DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + 7] + + this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[157] - 1; + this->AlphaGFXLayer[tile] = 0; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_STOCKPILE + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_QUARRYSTOCKPILE) { + if (stored > 0) { + int const pileGfx = DAT_TerrainDefinedData::instance + .field_0x84c[DAT_BuildingsState::instance.buildings[buildingID] + .currentStoredResourceType]; + int pile; + if (DAT_TerrainDefinedData::instance + .field_0x8b4[DAT_BuildingsState::instance.buildings[buildingID].currentStoredResourceType] + == 2) { + int const remaining + = DAT_BuildingsState::instance.buildings[buildingID].currentLimitOfResource - stored; + pile = this->buildingOrientedPartIndex + (remaining / 4 + (remaining & 3) * 12) * 4; + } else if (DAT_TerrainDefinedData::instance.field_0x8b4 + [DAT_BuildingsState::instance.buildings[buildingID].currentStoredResourceType] + != 0) { + pile = this->buildingOrientedPartIndex + + (DAT_BuildingsState::instance.buildings[buildingID].currentLimitOfResource - stored) * 4; + } else { + pile = this->buildingOrientedPartIndex - 4 + stored * 4; + } + this->GfxLayer[tile] = GMFirstPictureIndex::instance[15] + pileGfx + pile - 1; + } else { + this->GfxLayer[tile] = this->buildingOrientedPartIndex + GMFirstPictureIndex::instance[15] + 4; + } + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_MERCENARYPOST + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_BARRACKS + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_OUTPOST_EUROPEAN) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID].spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].spriteID + this->buildingOrientedPartIndex - 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_KEEPDOOR_LEFT + || DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_KEEPDOOR_RIGHT) { + int facing = this->mapOrientation; + if (DAT_BuildingsState::instance.buildings[buildingID].orientation == MO_WEST + || DAT_BuildingsState::instance.buildings[buildingID].orientation == MO_EAST) { + facing = (facing + 2) % MO_UPPER_LIMIT; + } + if (DAT_BuildingsState::instance.buildings[buildingID].useOffsetGraphics != 0) { + if (facing != MO_EAST && facing != MO_WEST) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset; + } + } else if (facing != MO_EAST && facing != MO_WEST) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated + + DAT_BuildingsState::instance.buildings[buildingID].spriteID - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated + + DAT_BuildingsState::instance.buildings[buildingID].spriteID; + } + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_KEEPDOOR) { + if (DAT_BuildingsState::instance.buildings[buildingID].useOffsetGraphics != 0) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset - 1; + } else if (this->mapOrientation != MO_EAST && this->mapOrientation != MO_WEST) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated + + DAT_BuildingsState::instance.buildings[buildingID].spriteID - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated + + DAT_BuildingsState::instance.buildings[buildingID].spriteID; + } + } else if (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) { + int variation; + if (this->mapOrientation != MO_EAST && this->mapOrientation != MO_WEST) { + variation = DAT_BuildingsState::instance.buildings[buildingID].buildingVariation; + } else { + variation = (DAT_BuildingsState::instance.buildings[buildingID].buildingVariation == 80) + 80; + } + if (DAT_BuildingsState::instance.buildings[buildingID].useOffsetGraphics != 0) { + if (variation == 80) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset + + this->buildingOrientedPartIndex - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset3 + + this->buildingOrientedPartIndex - 1; + } + } else if (variation == 80) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].spriteID + this->buildingOrientedPartIndex + - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset2 + + this->buildingOrientedPartIndex - 1; + } + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_MANORHOUSE) { + int variation; + if (this->mapOrientation != MO_EAST && this->mapOrientation != MO_WEST) { + variation = 80; + } else { + variation = 81; + } + if (DAT_BuildingsState::instance.buildings[buildingID].useOffsetGraphics != 0) { + if (variation == 80) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset + + this->buildingOrientedPartIndex - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + this->buildingOrientedPartIndex + 664; + } + } else if (variation == 80) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].spriteID + this->buildingOrientedPartIndex + - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + this->buildingOrientedPartIndex + 566; + } + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingType + == OpenSHC::Map::Buildings::BT_DRAWBRIDGE) { + int const plank = DAT_TerrainDefinedData::instance + .field_0x1fec[DAT_BuildingsState::instance.buildings[buildingID].buildingVariation + / 2][index]; + if (plank != 0) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + plank + 1566; + } else if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, this)(tile) != 0) { + this->GfxLayer[tile] = (this->RandomLayer[tile] & 3) + (this->LuminesenceLayer[tile] + 51) * 4 + + GMFirstPictureIndex::instance[5]; + } else { + this->GfxLayer[tile] = (this->RandomLayer[tile] & 3) + this->LuminesenceLayer[tile] * 4 + + GMFirstPictureIndex::instance[2]; + } + } else if ((DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_KILLINGPIT + || DAT_BuildingsState::instance.buildings[buildingID].state > 0 + || DAT_GameState::instance.mapAndTime + .playerTeams[DAT_BuildingsState::instance.buildings[buildingID].owner] + == DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + || DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR) + && DAT_BuildingsState::instance.buildings[buildingID].buildingType + != OpenSHC::Map::Buildings::BT_SIEGETOWER_PLACED) { + if (DAT_BuildingsState::instance.buildings[buildingID].buildingVariation != MO_NONE) { + int rotation + = DAT_BuildingsState::instance.buildings[buildingID].buildingVariation - this->mapOrientation; + if (rotation < 0) { + rotation += MO_UPPER_LIMIT; + } + int span; + if (DAT_BuildingsState::instance.buildings[buildingID].buildingVariation == 8) { + rotation = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; + span = DAT_BuildingsState::instance.buildings[buildingID].buildingVariation * rotation; + } else { + span = DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight + * DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight; + } + int const offset = span * rotation; + if (DAT_BuildingsState::instance.buildings[buildingID].buildingIsVisuallyActive != 0) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].visuallyActiveSpriteID + + this->buildingOrientedPartIndex + offset - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].spriteID + + this->buildingOrientedPartIndex + offset - 1; + } + this->AlphaGFXLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].spriteID + this->buildingOrientedPartIndex + + offset - 1; + } else { + if (DAT_BuildingsState::instance.buildings[buildingID].useOffsetGraphics != 0) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].gfxOffset + + this->buildingOrientedPartIndex - 1; + } else if (DAT_BuildingsState::instance.buildings[buildingID].buildingIsVisuallyActive != 0) { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].visuallyActiveSpriteID + + this->buildingOrientedPartIndex - 1; + } else { + this->GfxLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated + + DAT_BuildingsState::instance.buildings[buildingID].spriteID + + this->buildingOrientedPartIndex - 1; + } + this->AlphaGFXLayer[tile] + = GMFirstPictureIndex::instance[DAT_BuildingsState::instance.buildings[buildingID] + .spriteSheetID] + + DAT_BuildingsState::instance.buildings[buildingID].unknownManorHouseOrStoneKeepRelated + + DAT_BuildingsState::instance.buildings[buildingID].spriteID + this->buildingOrientedPartIndex + - 1; + } + } + } while (++index < this->constructionTileCount); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateGFXLayers.cpp b/src/OpenSHC/Map/TileMapState/updateGFXLayers.cpp new file mode 100644 index 0000000000..18b5140330 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateGFXLayers.cpp @@ -0,0 +1,321 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/Enums/NeighbourMask.hpp" +#include "OpenSHC/Map/LogicHelpers/MacroLayerTile.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/TileMapState/NeighbourFlagsGlobalAsm.hpp" + +#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.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::Enums::NM_CARDINALS; + 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::L2_STONES_OR_DRIVEN_SANDUnk; + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_DEFAULT_EARTH_OR_TEXTURE; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::MLT_EDGE; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_2X2; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_3X3; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_4X4; + using OpenSHC::Map::LogicHelpers::MLT_PART_MASK; + using OpenSHC::Map::LogicHelpers::MLT_PLAIN; + using OpenSHC::Map::LogicHelpers::MLT_SIZE_MASK; + using OpenSHC::Map::LogicHelpers::MLT_VARIANT_MASK; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FC9E0 + void TileMapState::updateGFXLayers() + { + int rotation; + int sectorColumn; + int partIndex; + int drawMode; + int tileRow; + int perLevel; + int luminescence; + int lowGfx; + int sectorRow; + int macroTop; + int macroSizeType; + int edgeBase; + int tileColumn; + int elevation; + int macroBase; + int priorBitFlag; + int macroMid; + int flatFrame; + int cornerFrame; + + if (this->forceUpdateGFXLayers <= 0) { + return; + } + this->forceUpdateGFXLayers--; + + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::getYSmallerThanYLimit, + &DAT_PathFindingState::instance)() + == FALSE) { + return; + } + + rotation = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (sectorRow = this->someIndex; sectorRow <= this->someLimit; sectorRow++) { + for (sectorColumn = this->someYLike; sectorColumn <= this->someYLikeLimit; sectorColumn++) { + if (DAT_TileMapState::instance.mapping40x40[sectorRow][sectorColumn] != 0) { + tileRow = rotation; + rotation = 0; + for (; tileRow < MC_MAP_SECTOR_SIZE; tileRow++) { + for (tileColumn = 0, this->DAT_SomeY = sectorRow * MC_MAP_SECTOR_SIZE + tileRow, + this->DAT_SomeX = sectorColumn * MC_MAP_SECTOR_SIZE; + tileColumn < MC_MAP_SECTOR_SIZE; tileColumn++, this->DAT_SomeX++) { + if (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY) + == FALSE) { + continue; + } + this->DAT_SomeTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY); + if ((this->LogicLayer[this->DAT_SomeTile] & L_DEFAULT_EARTH_OR_TEXTURE) == 0) { + continue; + } + if (this->GfxLayer[this->DAT_SomeTile] != 0) { + continue; + } + luminescence = this->LuminesenceLayer[this->DAT_SomeTile]; + if (luminescence < 2) { + luminescence = 2; + } + macroSizeType = this->MacroLayer[this->DAT_SomeTile] & MLT_SIZE_MASK; + macroMid = (this->MacroLayer[this->DAT_SomeTile] & MLT_PART_MASK) >> 6; + macroTop = (this->MacroLayer[this->DAT_SomeTile] & MLT_VARIANT_MASK) >> 12; + macroTop &= 3; + this->PillarGFXLayer[this->DAT_SomeTile] + = *(int volatile*)&GMFirstPictureIndex::instance[9]; + + if ((this->LogicLayer[this->DAT_SomeTile] & L_MARSH) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_4(1, L_MARSH) + edgeBase = 1; + cornerFrame = 3; + flatFrame = 21; + lowGfx = 33; + macroBase = 37; + perLevel = 4; + drawMode = 0; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_EARTH_AND_STONES) != 0) { + elevation = this->HeightLayer[this->DAT_SomeTile]; + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(2, L2_EARTH_AND_STONES) + edgeBase = 153; + cornerFrame = 155; + flatFrame = 173; + lowGfx = 185; + macroBase = 189; + perLevel = 4; + drawMode = 0; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_OASIS_GRASS) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(3, L2_OASIS_GRASS) + edgeBase = 457; + cornerFrame = 459; + flatFrame = 477; + lowGfx = 489; + macroBase = 493; + perLevel = 4; + drawMode = 0; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_STONES_OR_DRIVEN_SANDUnk) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(4, L2_STONES_OR_DRIVEN_SANDUnk) + edgeBase = 609; + cornerFrame = 611; + flatFrame = 629; + lowGfx = 641; + macroBase = 645; + perLevel = 4; + drawMode = 0; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_SCRUB) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(5, L2_SCRUB) + edgeBase = 761; + cornerFrame = 763; + flatFrame = 781; + lowGfx = 793; + macroBase = 797; + perLevel = 4; + drawMode = 0; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_THICK_SCRUB) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(6, L2_SCRUB) + edgeBase = 1193; + cornerFrame = 1195; + flatFrame = 1213; + lowGfx = 1225; + macroBase = 1229; + perLevel = 4; + drawMode = 0; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_PLATEAU_MEDIUM) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(7, L2_PLATEAU_MEDIUM) + edgeBase = 305; + cornerFrame = 307; + flatFrame = 325; + lowGfx = 337; + macroBase = 341; + perLevel = 4; + drawMode = 2; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_PLATEAU_HIGH) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(8, L2_PLATEAU_HIGH) + edgeBase = 305; + cornerFrame = 307; + flatFrame = 325; + lowGfx = 337; + macroBase = 341; + perLevel = 4; + drawMode = 2; + } else if ((this->Logic2Layer[this->DAT_SomeTile] & L2_BEACH) != 0) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_4(9, L2_BEACH) + priorBitFlag = this->bitFlag; + MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_4(10, L_SEA) + this->bitFlag |= priorBitFlag; + edgeBase = 913; + cornerFrame = 915; + flatFrame = 933; + lowGfx = 945; + macroBase = 949; + perLevel = 4; + drawMode = 0; + } else { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_4(11, L_DEFAULT_EARTH_OR_TEXTURE) + edgeBase = 305; + cornerFrame = 307; + flatFrame = 325; + lowGfx = 337; + macroBase = 341; + perLevel = 4; + drawMode = 2; + } + + if (macroSizeType == MLT_EDGE) { + this->bitFlag = ~this->bitFlag; + this->bitFlag &= NM_CARDINALS; + if (this->mapOrientation == OpenSHC::Map::Enums::MO_NORTH) { + this->bitFlag = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::rotateByteLeft, + &DAT_DirectionAlgorithmState::instance)(this->bitFlag, 0); + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_EAST) { + this->bitFlag = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::rotateByteLeft, + &DAT_DirectionAlgorithmState::instance)(this->bitFlag, 2); + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_SOUTH) { + this->bitFlag = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::rotateByteLeft, + &DAT_DirectionAlgorithmState::instance)(this->bitFlag, 4); + } else if (this->mapOrientation == OpenSHC::Map::Enums::MO_WEST) { + this->bitFlag = MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::DirectionAlgorithmState_Func::rotateByteLeft, + &DAT_DirectionAlgorithmState::instance)(this->bitFlag, 6); + } + + if (drawMode == 1) { + this->GfxLayer[this->DAT_SomeTile] = 0; + for (partIndex = 0; partIndex < 4; partIndex++) { + if (DAT_TerrainDefinedData::instance.TerrainEdgeGraphicLookup[partIndex].unk1 + == this->bitFlag) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + + edgeBase + ((luminescence - 2) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 1) + + DAT_TerrainDefinedData::instance.TerrainEdgeGraphicLookup[partIndex] + .unk2; + } + } + for (partIndex = 4; partIndex < 8; partIndex++) { + if (DAT_TerrainDefinedData::instance.TerrainEdgeGraphicLookup[partIndex].unk1 + == this->bitFlag) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + + cornerFrame + ((luminescence - 2) * perLevel - 1) + + DAT_TerrainDefinedData::instance.TerrainEdgeGraphicLookup[partIndex] + .unk2; + } + } + if (this->GfxLayer[this->DAT_SomeTile] == 0) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + + flatFrame + ((luminescence - 2) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 3); + } + } else if (luminescence == 2) { + if (this->bitFlag != 0) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + + flatFrame + (this->RandomLayer[this->DAT_SomeTile] & 7) - 1; + } else { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + lowGfx + + (this->RandomLayer[this->DAT_SomeTile] & 7) - 1; + } + } else if (drawMode == 2) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + edgeBase + + ((luminescence - 3) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 3); + } else if (this->bitFlag != 0) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + edgeBase + + ((luminescence - 3) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 1); + } else { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + cornerFrame + + ((luminescence - 3) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 1); + } + } else if (luminescence > 2) { + if (drawMode == 0) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + cornerFrame + + ((luminescence - 3) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 1); + } else if (drawMode == 2) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + edgeBase + + ((luminescence - 3) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 3); + } else { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + lowGfx + + ((luminescence - 2) * perLevel - 1) + + (this->RandomLayer[this->DAT_SomeTile] & 3); + } + } else if (macroSizeType == MLT_PLAIN) { + if (drawMode == 0) { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + lowGfx + + (this->RandomLayer[this->DAT_SomeTile] & 7) - 1; + } else { + this->GfxLayer[this->DAT_SomeTile] = GMFirstPictureIndex::instance[55] + lowGfx + + (this->RandomLayer[this->DAT_SomeTile] & 3) - 1; + } + } else if (macroSizeType == MLT_MACRO_2X2) { + macroMid = DAT_TerrainDefinedData::instance + .MacroLayerPartFrameOffsets[0][this->mapOrientation / 2][macroMid]; + this->GfxLayer[this->DAT_SomeTile] + = GMFirstPictureIndex::instance[55] + macroBase + macroMid + macroTop * 4 - 1; + } else if (macroSizeType == MLT_MACRO_3X3) { + macroMid = DAT_TerrainDefinedData::instance + .MacroLayerPartFrameOffsets[1][this->mapOrientation / 2][macroMid]; + this->GfxLayer[this->DAT_SomeTile] + = GMFirstPictureIndex::instance[55] + macroBase + macroTop * 9 + macroMid + 15; + } else if (macroSizeType == MLT_MACRO_4X4) { + macroMid = DAT_TerrainDefinedData::instance + .MacroLayerPartFrameOffsets[2][this->mapOrientation / 2][macroMid]; + this->GfxLayer[this->DAT_SomeTile] + = GMFirstPictureIndex::instance[55] + macroBase + macroTop * 16 + macroMid + 51; + } + } + } + } + } + } + } +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateLogicalTileMapRelatedSections.cpp b/src/OpenSHC/Map/TileMapState/updateLogicalTileMapRelatedSections.cpp new file mode 100644 index 0000000000..877a92e803 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateLogicalTileMapRelatedSections.cpp @@ -0,0 +1,355 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Enums/CardinalDirection.hpp" +#include "OpenSHC/Map/LogicHelpers/MiscDisplay.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.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::Enums::CD_UPPER_LIMIT; + 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::L2_STONES_OR_DRIVEN_SANDUnk; + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_CRENEL; + using OpenSHC::Map::LogicHelpers::L_DEFAULT_EARTH_OR_TEXTURE; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_HOP; + using OpenSHC::Map::LogicHelpers::L_FARM_FIELD_WHEAT; + using OpenSHC::Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE; + using OpenSHC::Map::LogicHelpers::L_MOAT; + using OpenSHC::Map::LogicHelpers::L_RIVER; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_STAIRS; + using OpenSHC::Map::LogicHelpers::L_STOCKPILEUnk; + using OpenSHC::Map::LogicHelpers::L_TREE_VARIATION; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + using OpenSHC::Map::LogicHelpers::MD_BATCHED_SPRITES; + using OpenSHC::Map::LogicHelpers::MD_PILLAR_EAST_SIDEUnk; + using OpenSHC::Map::LogicHelpers::MD_PILLAR_SIDESUnk; + using OpenSHC::Map::LogicHelpers::MD_PILLAR_SOUTH_SIDEUnk; + + // FUNCTION: STRONGHOLDCRUSADER 0x004F70F0 + void TileMapState::updateLogicalTileMapRelatedSections() + { + if (this->forceUpdateLogicalAndMiscDisplayLayers == 0) { + return; + } + this->forceUpdateLogicalAndMiscDisplayLayers = 0; + int tile = DAT_ViewportRenderState::instance.translationMatrix[DAT_PathFindingState::instance.mappingYRelated] + .firstTileOfRow; + DAT_BuildingsState::instance.field_0x18e074 = 1; + for (int row = DAT_PathFindingState::instance.mappingYRelated; + row < MC_MAP_XY_LIMIT && row <= DAT_PathFindingState::instance.yLimit; row++) { + int const columns = this->yArray1[row]; + for (int column = 0; column < columns; column++, tile++) { + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0 || this->ChangedLayer[tile] == 0) { + continue; + } + + int const height = this->HeightLayer[tile]; + int const screenY = this->heightBasedScreenYOffset[height]; + this->ShowHiLayer[tile] = 0; + this->MiscDisplayLayer[tile] &= ~MD_BATCHED_SPRITES; + if (height == 0 + && ((this->LogicLayer[tile] & L_RIVER) != 0 || (this->Logic2Layer[tile] & L2_BEACH) == 0) + && (this->LogicLayer[tile] & L_MOAT) == 0) { + this->LogicLayer[tile] &= ~L_DEFAULT_EARTH_OR_TEXTURE; + } else if (height <= 8) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if ((this->Logic2Layer[tile] & L2_PLATEAU_MEDIUM) != 0) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if ((this->Logic2Layer[tile] & L2_PLATEAU_HIGH) != 0) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if ((this->Logic2Layer[tile] & L2_EARTH_AND_STONES) != 0) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if ((this->Logic2Layer[tile] & L2_OASIS_GRASS) != 0) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if ((this->Logic2Layer[tile] & L2_SCRUB) != 0) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if ((this->Logic2Layer[tile] & L2_THICK_SCRUB) != 0) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if ((this->Logic2Layer[tile] & L2_STONES_OR_DRIVEN_SANDUnk) != 0) { + this->LogicLayer[tile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else { + this->LogicLayer[tile] &= ~L_DEFAULT_EARTH_OR_TEXTURE; + } + + for (int i = 0; i < CD_UPPER_LIMIT; i++) { + int const neighbour = this->directionTranslationMatrix[row][i] + tile; + int const neighbourHeight = this->HeightLayer[neighbour]; + if ((height > 8 || neighbourHeight == 0) && height != neighbourHeight) { + if ((this->LogicLayer[neighbour] & (L_RIVER | L_MOAT)) == 0) { + this->LogicLayer[tile] &= ~L_DEFAULT_EARTH_OR_TEXTURE; + } + break; + } + } + int const building = this->BuildingLayer[tile]; + if (building != 0 + && DAT_BuildingsState::instance.buildings[building].buildingType + == OpenSHC::Map::Buildings::BT_DRAWBRIDGE) { + this->MiscDisplayLayer[tile] |= MD_BATCHED_SPRITES; + } + + if (this->disableElevationRendering == 0) { + int walkTile = tile; + for (int step = 0; step < 8; step++) { + walkTile += this->directionTranslationMatrix[row + step * this->orientedRowStep] + [this->screenSouthEastDirection]; + if ((this->LogicLayer[walkTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + break; + } + if (screenY <= this->heightBasedScreenYOffset[this->HeightLayer[walkTile]] - step * 16 - 16) { + this->ShowHiLayer[tile] = 255; + break; + } + } + if (height == 0) { + continue; + } + if (this->ShowHiLayer[tile] == 255) { + continue; + } + } else { + this->ShowHiLayer[tile] = 8; + } + + BOOLEnum occluded; + if ((this->LogicLayer[tile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0) { + occluded = TRUE; + } else if ((this->LogicLayer[tile] & L_TREE_VARIATION) != 0) { + occluded = TRUE; + } else if ((this->LogicLayer[tile] & L_FARM_FIELD_WHEAT) != 0) { + occluded = TRUE; + } else if ((this->LogicLayer[tile] & L_FARM_FIELD_HOP) != 0) { + occluded = TRUE; + } else if ((this->LogicLayer[tile] & L_CRENEL) != 0) { + occluded = TRUE; + } else if ((this->LogicLayer[tile] & L_STAIRS) != 0) { + occluded = TRUE; + } else { + this->MiscDisplayLayer[tile] |= MD_BATCHED_SPRITES; + occluded = FALSE; + } + for (int i = 0; i < CD_UPPER_LIMIT; i++) { + int const neighbour = this->directionTranslationMatrix[row][i] + tile; + if ((height > 8 && height != this->HeightLayer[neighbour]) + || (this->LogicLayer[neighbour] & L_TREE_VARIATION) != 0) { + this->MiscDisplayLayer[tile] &= ~MD_BATCHED_SPRITES; + break; + } + if ((this->LogicLayer[neighbour] & L_FARM_FIELD_WHEAT) != 0) { + occluded = TRUE; + } + if ((this->LogicLayer[neighbour] & L_FARM_FIELD_HOP) != 0) { + occluded = TRUE; + } + } + this->MiscDisplayLayer[tile] &= ~MD_PILLAR_SIDESUnk; + + BOOLEnum stepRight = FALSE; + BOOLEnum stepLeft = FALSE; + int shadowTile = this->directionTranslationMatrix[row][this->screenSouthEastDirection] + tile; + int lowest = 250; + if (this->heightBasedScreenYOffset[this->HeightLayer[shadowTile]] < 250) { + lowest = this->heightBasedScreenYOffset[this->HeightLayer[shadowTile]]; + } + int const nearly = screenY + 2; + if (this->heightBasedScreenYOffset[this->HeightLayer[shadowTile]] > nearly) { + occluded = TRUE; + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + if (DAT_BuildingsState::instance.buildings[this->BuildingLayer[shadowTile]].flag2 != 0) { + occluded = TRUE; + } + if (DAT_BuildingsState::instance.buildings[this->BuildingLayer[shadowTile]].buildingType + == OpenSHC::Map::Buildings::BT_STOCKPILE) { + occluded = TRUE; + } + if (DAT_BuildingsState::instance + .buildings[this->BuildingLayer[this->directionTranslationMatrix[this->orientedRowStep + + row][this->screenSouthEastDirection] + + shadowTile]] + .flag2 + != 0) { + occluded = TRUE; + } + } else { + if ((this->LogicLayer[shadowTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[shadowTile]) + != 0) { + occluded = TRUE; + } + int const southTile = this->directionTranslationMatrix[row][this->screenSouthDirection] + tile; + if (((this->LogicLayer[southTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[southTile]) + != 0) + || ((this->LogicLayer[southTile] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[southTile] & L_STOCKPILEUnk) == 0)) { + occluded = TRUE; + } + int const eastTile = this->directionTranslationMatrix[row][this->screenEastDirection] + tile; + if (((this->LogicLayer[eastTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[eastTile]) + != 0) + || ((this->LogicLayer[eastTile] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[eastTile] & L_STOCKPILEUnk) == 0)) { + occluded = TRUE; + } + int const southTile2 + = this->directionTranslationMatrix[this->orientedRowStep + row][this->screenSouthDirection] + + shadowTile; + if (((this->LogicLayer[southTile2] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[southTile2]) + != 0) + || ((this->LogicLayer[southTile2] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[southTile2] & L_STOCKPILEUnk) == 0)) { + occluded = TRUE; + } + int const eastTile2 + = this->directionTranslationMatrix[this->orientedRowStep + row][this->screenEastDirection] + + shadowTile; + if (((this->LogicLayer[eastTile2] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[eastTile2]) + != 0) + || ((this->LogicLayer[eastTile2] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[eastTile2] & L_STOCKPILEUnk) == 0)) { + occluded = TRUE; + } + shadowTile += this->directionTranslationMatrix[this->orientedRowStep + row] + [this->screenSouthEastDirection]; + if ((this->LogicLayer[shadowTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[shadowTile]) + != 0) { + occluded = TRUE; + } + int const southTile3 + = this->directionTranslationMatrix[row + this->orientedRowStep * 2][this->screenSouthDirection] + + shadowTile; + if (((this->LogicLayer[southTile3] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[southTile3]) + != 0) + || ((this->LogicLayer[southTile3] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[southTile3] & L_STOCKPILEUnk) == 0)) { + occluded = TRUE; + } + int const eastTile3 + = this->directionTranslationMatrix[row + this->orientedRowStep * 2][this->screenEastDirection] + + shadowTile; + if (((this->LogicLayer[eastTile3] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[eastTile3]) + != 0) + || ((this->LogicLayer[eastTile3] & L_WALL_OR_GATEHOUSE) != 0 + && (this->LogicLayer[eastTile3] & L_STOCKPILEUnk) == 0)) { + occluded = TRUE; + } + shadowTile += this->directionTranslationMatrix[row + this->orientedRowStep * 2] + [this->screenSouthEastDirection]; + if ((this->LogicLayer[shadowTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[shadowTile]) + != 0) { + occluded = TRUE; + } + } + + int const southTile = this->directionTranslationMatrix[row][this->screenSouthDirection] + tile; + if (this->heightBasedScreenYOffset[this->HeightLayer[southTile]] < lowest) { + lowest = this->heightBasedScreenYOffset[this->HeightLayer[southTile]]; + } + if (this->heightBasedScreenYOffset[this->HeightLayer[southTile]] >= screenY) { + stepLeft = TRUE; + if (this->heightBasedScreenYOffset[this->HeightLayer[southTile]] > nearly) { + occluded = TRUE; + } + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + if (DAT_BuildingsState::instance.buildings[this->BuildingLayer[southTile]].flag2 != 0) { + occluded = TRUE; + } + if (DAT_BuildingsState::instance.buildings[this->BuildingLayer[southTile]].buildingType + == OpenSHC::Map::Buildings::BT_STOCKPILE) { + occluded = TRUE; + } + } else { + if ((this->LogicLayer[southTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[southTile]) + != 0) { + occluded = TRUE; + } + } + + int const eastTile = this->directionTranslationMatrix[row][this->screenEastDirection] + tile; + if (this->heightBasedScreenYOffset[this->HeightLayer[eastTile]] < lowest) { + lowest = this->heightBasedScreenYOffset[this->HeightLayer[eastTile]]; + } + if (this->heightBasedScreenYOffset[this->HeightLayer[eastTile]] >= screenY) { + stepRight = TRUE; + if (this->heightBasedScreenYOffset[this->HeightLayer[eastTile]] > nearly) { + occluded = TRUE; + } + } + if ((this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0) { + if (DAT_BuildingsState::instance.buildings[this->BuildingLayer[eastTile]].flag2 != 0) { + occluded = TRUE; + } + if (DAT_BuildingsState::instance.buildings[this->BuildingLayer[eastTile]].buildingType + == OpenSHC::Map::Buildings::BT_STOCKPILE) { + occluded = TRUE; + } + } else if ((this->LogicLayer[tile] & L_KEEP_NON_MANOR_HOUSE) == 0 + && (this->LogicLayer[eastTile] & (L_BUILDING | L_KEEP_NON_MANOR_HOUSE)) != 0 + && MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingFlag1, + DAT_BuildingsState::ptr)(this->BuildingLayer[eastTile]) + != 0) { + occluded = TRUE; + } + if (!occluded) { + this->MiscDisplayLayer[tile] |= MD_BATCHED_SPRITES; + } else { + this->MiscDisplayLayer[tile] &= ~MD_BATCHED_SPRITES; + } + + if (screenY > lowest) { + if (this->disableElevationRendering == 0) { + this->ShowHiLayer[tile] = screenY - lowest; + } + if ((this->LogicLayer[tile] & L_SEA) == 0) { + if (stepLeft) { + this->MiscDisplayLayer[tile] |= MD_PILLAR_SOUTH_SIDEUnk; + } + if (stepRight) { + this->MiscDisplayLayer[tile] |= MD_PILLAR_EAST_SIDEUnk; + } + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateMacroLayerRelated.cpp b/src/OpenSHC/Map/TileMapState/updateMacroLayerRelated.cpp new file mode 100644 index 0000000000..ce88130a72 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateMacroLayerRelated.cpp @@ -0,0 +1,335 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Rendering/ViewportRenderState.func.hpp" +#include "OpenSHC/Map/Enums/NeighbourMask.hpp" +#include "OpenSHC/Map/LogicHelpers/MacroLayerTile.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/TileMapState/NeighbourFlagsGlobalAsm.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.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::Enums::NM_ALL; + 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::L2_STONES_OR_DRIVEN_SANDUnk; + using OpenSHC::Map::LogicHelpers::L2_THICK_SCRUB; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_DEFAULT_EARTH_OR_TEXTURE; + using OpenSHC::Map::LogicHelpers::L_MARSH; + using OpenSHC::Map::LogicHelpers::L_OIL; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::MLT_EDGE; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_2X2; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_3X3; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_4X4; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_CANDIDATE; + using OpenSHC::Map::LogicHelpers::MLT_PART_STEP; + using OpenSHC::Map::LogicHelpers::MLT_PLAIN; + using OpenSHC::Map::LogicHelpers::MLT_VARIANT_STEP; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FDB00 + void TileMapState::updateMacroLayerRelated(uint logic1, uint logic2, int clearMacroFirst) + { + int oldMacro; + int rotation; + int sectorColumn; + int tileRow; + int offsetTile; + int sectorRow; + int scanIndex; + int savedBitFlag; + int tileX; + int offsetX; + int randomVal; + int tableY; + int tileColumn; + + rotation = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (sectorRow = this->someIndex; sectorRow <= this->someLimit; sectorRow++) { + for (sectorColumn = this->someYLike; sectorColumn <= this->someYLikeLimit; sectorColumn++) { + if (DAT_TileMapState::instance.mapping40x40[sectorRow][sectorColumn] != 0) { + tileRow = rotation; + rotation = 0; + for (; tileRow < MC_MAP_SECTOR_SIZE; tileRow++) { + for (tileColumn = 0, this->DAT_SomeY = sectorRow * MC_MAP_SECTOR_SIZE + tileRow, + this->DAT_SomeX = sectorColumn * MC_MAP_SECTOR_SIZE; + tileColumn < MC_MAP_SECTOR_SIZE; tileColumn++, this->DAT_SomeX++) { + if (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY) + == FALSE) { + continue; + } + this->DAT_SomeTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY); + if (this->ChangedLayer[this->DAT_SomeTile] == 0) { + continue; + } + oldMacro = this->MacroLayer[this->DAT_SomeTile]; + if (clearMacroFirst != 0) { + this->MacroLayer[this->DAT_SomeTile] = 0; + } + if ((this->LogicLayer[this->DAT_SomeTile] & logic1) != 0) { + } else if ((this->Logic2Layer[this->DAT_SomeTile] & logic2) != 0) { + } else { + continue; + } + if ((this->LogicLayer[this->DAT_SomeTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + this->bitFlag = 0; + } else if (logic1 == L_DEFAULT_EARTH_OR_TEXTURE) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_8(1, L_DEFAULT_EARTH_OR_TEXTURE) + } else if (logic1 == L_MARSH) { + if ((this->LogicLayer[this->DAT_SomeTile] & L_OIL) != 0) { + continue; + } + MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_8(2, L_MARSH) + } else if (logic2 == L2_EARTH_AND_STONES) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(3, L2_EARTH_AND_STONES) + } else if (logic2 == L2_OASIS_GRASS) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(4, L2_OASIS_GRASS) + } else if (logic2 == L2_SCRUB) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(5, L2_SCRUB) + } else if (logic2 == L2_THICK_SCRUB) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(6, L2_THICK_SCRUB) + } else if (logic2 == L2_STONES_OR_DRIVEN_SANDUnk) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(7, L2_STONES_OR_DRIVEN_SANDUnk) + } else if (logic2 == L2_BEACH) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(8, L2_BEACH) + savedBitFlag = this->bitFlag; + MACRO_NEIGHBOUR_FLAGS_GLOBAL_LOGIC_8(9, L_SEA) + this->bitFlag |= savedBitFlag; + } else if (logic2 == L2_PLATEAU_MEDIUM) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(10, L2_PLATEAU_MEDIUM) + } else if (logic2 == L2_PLATEAU_HIGH) { + MACRO_NEIGHBOUR_FLAGS_GLOBAL_TERRAIN_8(11, L2_PLATEAU_HIGH) + } else { + this->bitFlag = 0; + } + if (this->bitFlag != NM_ALL) { + this->MacroLayer[this->DAT_SomeTile] = MLT_EDGE; + } else if ((this->RandomLayer[this->DAT_SomeTile] & 0xf) == 0) { + this->MacroLayer[this->DAT_SomeTile] = MLT_PLAIN; + } else { + this->MacroLayer[this->DAT_SomeTile] = MLT_MACRO_CANDIDATE; + } + if (oldMacro != this->MacroLayer[this->DAT_SomeTile]) { + MACRO_CALL_MEMBER( + OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + &DAT_PathFindingState::instance)(1, this->DAT_SomeX, this->DAT_SomeY); + } + } + } + } + } + } + rotation = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (sectorRow = this->someIndex; sectorRow <= this->someLimit; sectorRow++) { + for (sectorColumn = this->someYLike; sectorColumn <= this->someYLikeLimit; sectorColumn++) { + if (DAT_TileMapState::instance.mapping40x40[sectorRow][sectorColumn] != 0) { + tileRow = rotation; + rotation = 0; + for (; tileRow < MC_MAP_SECTOR_SIZE; tileRow++) { + for (tileColumn = 0, this->DAT_SomeY = sectorRow * MC_MAP_SECTOR_SIZE + tileRow, + this->DAT_SomeX = sectorColumn * MC_MAP_SECTOR_SIZE; + tileColumn < MC_MAP_SECTOR_SIZE; tileColumn++, this->DAT_SomeX++) { + if (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY) + == FALSE) { + continue; + } + this->DAT_SomeTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY); + if (this->MacroLayer[this->DAT_SomeTile] != MLT_MACRO_CANDIDATE) { + continue; + } + tileX = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::computeTileXOffset, + &DAT_ViewportRenderState::instance)(this->DAT_SomeTile, this->DAT_SomeY); + randomVal = this->RandomLayer[this->DAT_SomeTile] & 0xf; + for (scanIndex = 0; + scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4); + scanIndex++) { + offsetX = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[scanIndex].x; + tableY = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[scanIndex].y; + offsetTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(tileX + offsetX, this->DAT_SomeY + tableY); + if (this->MacroLayer[offsetTile] != MLT_MACRO_CANDIDATE) { + break; + } + } + if (scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4)) { + continue; + } + for (scanIndex = 0; + scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4); + scanIndex++) { + offsetX = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[scanIndex].x; + tableY = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[scanIndex].y; + offsetTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(tileX + offsetX, this->DAT_SomeY + tableY); + this->MacroLayer[offsetTile] = MLT_MACRO_4X4; + this->MacroLayer[offsetTile] += scanIndex * MLT_PART_STEP; + this->MacroLayer[offsetTile] += randomVal * MLT_VARIANT_STEP; + } + } + } + } + } + } + rotation = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (sectorRow = this->someIndex; sectorRow <= this->someLimit; sectorRow++) { + for (sectorColumn = this->someYLike; sectorColumn <= this->someYLikeLimit; sectorColumn++) { + if (DAT_TileMapState::instance.mapping40x40[sectorRow][sectorColumn] != 0) { + tileRow = rotation; + rotation = 0; + for (; tileRow < MC_MAP_SECTOR_SIZE; tileRow++) { + for (tileColumn = 0, this->DAT_SomeY = sectorRow * MC_MAP_SECTOR_SIZE + tileRow, + this->DAT_SomeX = sectorColumn * MC_MAP_SECTOR_SIZE; + tileColumn < MC_MAP_SECTOR_SIZE; tileColumn++, this->DAT_SomeX++) { + if (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY) + == FALSE) { + continue; + } + this->DAT_SomeTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY); + if (this->MacroLayer[this->DAT_SomeTile] != MLT_MACRO_CANDIDATE) { + continue; + } + tileX = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::computeTileXOffset, + &DAT_ViewportRenderState::instance)(this->DAT_SomeTile, this->DAT_SomeY); + randomVal = this->RandomLayer[this->DAT_SomeTile] & 0xf; + for (scanIndex = 0; + scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets3x3); + scanIndex++) { + offsetX = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets3x3[scanIndex].x; + tableY = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets3x3[scanIndex].y; + offsetTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(tileX + offsetX, this->DAT_SomeY + tableY); + if (this->MacroLayer[offsetTile] != MLT_MACRO_CANDIDATE) { + break; + } + } + if (scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets3x3)) { + continue; + } + for (scanIndex = 0; + scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets3x3); + scanIndex++) { + offsetX = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets3x3[scanIndex].x; + tableY = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets3x3[scanIndex].y; + offsetTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(tileX + offsetX, this->DAT_SomeY + tableY); + this->MacroLayer[offsetTile] = MLT_MACRO_3X3; + this->MacroLayer[offsetTile] += scanIndex * MLT_PART_STEP; + this->MacroLayer[offsetTile] += randomVal * MLT_VARIANT_STEP; + } + } + } + } + } + } + rotation = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (sectorRow = this->someIndex; sectorRow <= this->someLimit; sectorRow++) { + for (sectorColumn = this->someYLike; sectorColumn <= this->someYLikeLimit; sectorColumn++) { + if (DAT_TileMapState::instance.mapping40x40[sectorRow][sectorColumn] != 0) { + tileRow = rotation; + rotation = 0; + for (; tileRow < MC_MAP_SECTOR_SIZE; tileRow++) { + for (tileColumn = 0, this->DAT_SomeY = sectorRow * MC_MAP_SECTOR_SIZE + tileRow, + this->DAT_SomeX = sectorColumn * MC_MAP_SECTOR_SIZE; + tileColumn < MC_MAP_SECTOR_SIZE; tileColumn++, this->DAT_SomeX++) { + if (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY) + == FALSE) { + continue; + } + this->DAT_SomeTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY); + if (this->MacroLayer[this->DAT_SomeTile] != MLT_MACRO_CANDIDATE) { + continue; + } + tileX = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::computeTileXOffset, + &DAT_ViewportRenderState::instance)(this->DAT_SomeTile, this->DAT_SomeY); + randomVal = this->RandomLayer[this->DAT_SomeTile] & 0xf; + for (scanIndex = 0; + scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets2x2); + scanIndex++) { + offsetX = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets2x2[scanIndex].x; + tableY = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets2x2[scanIndex].y; + offsetTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(tileX + offsetX, this->DAT_SomeY + tableY); + if (this->MacroLayer[offsetTile] != MLT_MACRO_CANDIDATE) { + break; + } + } + if (scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets2x2)) { + continue; + } + for (scanIndex = 0; + scanIndex < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets2x2); + scanIndex++) { + offsetX = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets2x2[scanIndex].x; + tableY = DAT_TerrainDefinedData::instance.MacroLayerScanOffsets2x2[scanIndex].y; + offsetTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(tileX + offsetX, this->DAT_SomeY + tableY); + this->MacroLayer[offsetTile] = MLT_MACRO_2X2; + this->MacroLayer[offsetTile] += scanIndex * MLT_PART_STEP; + this->MacroLayer[offsetTile] += randomVal * MLT_VARIANT_STEP; + } + } + } + } + } + } + rotation = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (sectorRow = this->someIndex; sectorRow <= this->someLimit; sectorRow++) { + for (sectorColumn = this->someYLike; sectorColumn <= this->someYLikeLimit; sectorColumn++) { + if (DAT_TileMapState::instance.mapping40x40[sectorRow][sectorColumn] != 0) { + tileRow = rotation; + rotation = 0; + for (; tileRow < MC_MAP_SECTOR_SIZE; tileRow++) { + for (tileColumn = 0, this->DAT_SomeY = sectorRow * MC_MAP_SECTOR_SIZE + tileRow, + this->DAT_SomeX = sectorColumn * MC_MAP_SECTOR_SIZE; + tileColumn < MC_MAP_SECTOR_SIZE; tileColumn++, this->DAT_SomeX++) { + if (MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::xyAreValid, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY) + == FALSE) { + continue; + } + this->DAT_SomeTile + = MACRO_CALL_MEMBER(OpenSHC::Rendering::ViewportRenderState_Func::translateXYToTile, + &DAT_ViewportRenderState::instance)(this->DAT_SomeX, this->DAT_SomeY); + if (this->MacroLayer[this->DAT_SomeTile] != MLT_MACRO_CANDIDATE) { + continue; + } + this->MacroLayer[this->DAT_SomeTile] = MLT_PLAIN; + } + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/updateMacroLayerRelated2.cpp b/src/OpenSHC/Map/TileMapState/updateMacroLayerRelated2.cpp new file mode 100644 index 0000000000..bbedddecac --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/updateMacroLayerRelated2.cpp @@ -0,0 +1,148 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LogicHelpers/MacroLayerTile.hpp" +#include "OpenSHC/Map/MapConstants.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.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_SEA; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_4X4; + using OpenSHC::Map::LogicHelpers::MLT_MACRO_CANDIDATE; + using OpenSHC::Map::LogicHelpers::MLT_PART_STEP; + using OpenSHC::Map::LogicHelpers::MLT_PLAIN; + using OpenSHC::Map::LogicHelpers::MLT_VARIANT_STEP; + + // FUNCTION: STRONGHOLDCRUSADER 0x004FF080 + void TileMapState::updateMacroLayerRelated2() + { + int block; + int sub; + int startRow = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (block = this->someIndex; block <= this->someLimit; block++) { + for (sub = this->someYLike; sub <= this->someYLikeLimit; sub++) { + if (DAT_TileMapState::instance.mapping40x40[block][sub] == 0) { + continue; + } + int row = startRow; + startRow = 0; + for (; row < MC_MAP_SECTOR_SIZE; row++) { + this->DAT_SomeY = block * MC_MAP_SECTOR_SIZE + row; + this->DAT_SomeX = sub * MC_MAP_SECTOR_SIZE; + for (int column = 0; column < MC_MAP_SECTOR_SIZE; column++, this->DAT_SomeX++) { + uint const x = this->DAT_SomeX; + uint const y = this->DAT_SomeY; + if (x > MC_MAP_XY_LIMIT_MIN_1 || y > MC_MAP_XY_LIMIT_MIN_1 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] + == 0) { + continue; + } + this->DAT_SomeTile + = DAT_ViewportRenderState::instance.translationMatrix[this->DAT_SomeY].addXgetTile + + this->DAT_SomeX; + if (this->ChangedLayer[this->DAT_SomeTile] != 0 + && (this->LogicLayer[this->DAT_SomeTile] & L_SEA) != 0) { + this->MacroLayer[this->DAT_SomeTile] = MLT_MACRO_CANDIDATE; + } + } + } + } + } + + startRow = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (block = this->someIndex; block <= this->someLimit; block++) { + for (sub = this->someYLike; sub <= this->someYLikeLimit; sub++) { + if (DAT_TileMapState::instance.mapping40x40[block][sub] == 0) { + continue; + } + int row = startRow; + startRow = 0; + for (; row < MC_MAP_SECTOR_SIZE; row++) { + this->DAT_SomeY = block * MC_MAP_SECTOR_SIZE + row; + this->DAT_SomeX = sub * MC_MAP_SECTOR_SIZE; + for (int column = 0; column < MC_MAP_SECTOR_SIZE; column++, this->DAT_SomeX++) { + uint const x = this->DAT_SomeX; + uint const y = this->DAT_SomeY; + if (x > MC_MAP_XY_LIMIT_MIN_1 || y > MC_MAP_XY_LIMIT_MIN_1 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] + == 0) { + continue; + } + this->DAT_SomeTile + = DAT_ViewportRenderState::instance.translationMatrix[this->DAT_SomeY].addXgetTile + + this->DAT_SomeX; + if (this->MacroLayer[this->DAT_SomeTile] != MLT_MACRO_CANDIDATE + || (this->LogicLayer[this->DAT_SomeTile] & L_SEA) == 0) { + continue; + } + int const corner = this->DAT_SomeTile + - DAT_ViewportRenderState::instance.translationMatrix[this->DAT_SomeY].addXgetTile; + int const random = this->RandomLayer[this->DAT_SomeTile] & 0xf; + int i; + for (i = 0; i < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4); i++) { + int const scanTile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[i].y + + this->DAT_SomeY] + .addXgetTile + + DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[i].x + corner; + if (this->MacroLayer[scanTile] != MLT_MACRO_CANDIDATE) { + break; + } + } + if (i < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4)) { + continue; + } + for (i = 0; i < countof(DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4); i++) { + int const scanTile + = DAT_ViewportRenderState::instance + .translationMatrix[DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[i].y + + this->DAT_SomeY] + .addXgetTile + + DAT_TerrainDefinedData::instance.MacroLayerScanOffsets4x4[i].x + corner; + this->MacroLayer[scanTile] = random * MLT_VARIANT_STEP; + this->MacroLayer[scanTile] += i * MLT_PART_STEP + MLT_MACRO_4X4; + } + } + } + } + } + + startRow = DAT_PathFindingState::instance.mappingYRelated % MC_MAP_SECTOR_SIZE; + for (block = this->someIndex; block <= this->someLimit; block++) { + for (sub = this->someYLike; sub <= this->someYLikeLimit; sub++) { + if (DAT_TileMapState::instance.mapping40x40[block][sub] == 0) { + continue; + } + int row = startRow; + startRow = 0; + for (; row < MC_MAP_SECTOR_SIZE; row++) { + this->DAT_SomeY = block * MC_MAP_SECTOR_SIZE + row; + this->DAT_SomeX = sub * MC_MAP_SECTOR_SIZE; + for (int column = 0; column < MC_MAP_SECTOR_SIZE; column++, this->DAT_SomeX++) { + uint const x = this->DAT_SomeX; + uint const y = this->DAT_SomeY; + if (x > MC_MAP_XY_LIMIT_MIN_1 || y > MC_MAP_XY_LIMIT_MIN_1 + || DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y * MC_MAP_XY_LIMIT + x] + == 0) { + continue; + } + this->DAT_SomeTile + = DAT_ViewportRenderState::instance.translationMatrix[this->DAT_SomeY].addXgetTile + + this->DAT_SomeX; + if (this->MacroLayer[this->DAT_SomeTile] == MLT_MACRO_CANDIDATE) { + this->MacroLayer[this->DAT_SomeTile] = MLT_PLAIN; + } + } + } + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/upgradeTowerLogicLayer.cpp b/src/OpenSHC/Map/TileMapState/upgradeTowerLogicLayer.cpp new file mode 100644 index 0000000000..a799b40d87 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/upgradeTowerLogicLayer.cpp @@ -0,0 +1,50 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.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; + + // FUNCTION: STRONGHOLDCRUSADER 0x00507280 + void TileMapState::upgradeTowerLogicLayer(int buildingID) + { + int buildingSizeTileIndex = 0; + do { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getBuildingSizeIndexMappingData, this)( + buildingSizeTileIndex, DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight); + int tile = DAT_ViewportRenderState::instance + .translationMatrix[DAT_BuildingsState::instance.buildings[buildingID].y + this->buildingY] + .addXgetTile + + DAT_BuildingsState::instance.buildings[buildingID].x + this->buildingX; + this->LogicLayer[tile] &= ~L_BUILDING; + if (DAT_TerrainDefinedData::instance + .TowerTileOffsetsBySize[DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight][0] + == buildingSizeTileIndex) { + this->LogicLayer[tile] |= L_BUILDING; + } else if (DAT_TerrainDefinedData::instance + .TowerTileOffsetsBySize[DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight][1] + == buildingSizeTileIndex) { + this->LogicLayer[tile] |= L_BUILDING; + } else if (DAT_TerrainDefinedData::instance + .TowerTileOffsetsBySize[DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight][2] + == buildingSizeTileIndex) { + this->LogicLayer[tile] |= L_BUILDING; + } else if (DAT_TerrainDefinedData::instance + .TowerTileOffsetsBySize[DAT_BuildingsState::instance.buildings[buildingID].widthOrHeight][3] + == buildingSizeTileIndex) { + this->LogicLayer[tile] |= L_BUILDING; + } else { + this->LogicLayer[tile] |= L_KEEP_NON_MANOR_HOUSE; + } + buildingSizeTileIndex++; + } while (buildingSizeTileIndex < this->constructionTileCount); + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::updatePathLinkagesForBuilding, this)(buildingID); + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/useEraserBrush.cpp b/src/OpenSHC/Map/TileMapState/useEraserBrush.cpp new file mode 100644 index 0000000000..908d7a2ca7 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/useEraserBrush.cpp @@ -0,0 +1,116 @@ +#include "../TileMapState.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/Game/Player/Enums/BuildingEntryInfoEnum.hpp" +#include "OpenSHC/Map/Buildings/BuildingType.hpp" +#include "OpenSHC/Map/Units/UnitLogicState.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BuildingsState.hpp" +#include "OpenSHC/Globals/DAT_EntityState.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" + +namespace OpenSHC { +namespace Map { + + // FUNCTION: STRONGHOLDCRUSADER 0x005017C0 + void TileMapState::useEraserBrush(int x, int y, int brush) + { + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[brush]; + int const baseTile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + int const baseY = y; + int tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + MACRO_CALL_MEMBER(OpenSHC::Map::Entities::EntityState_Func::destroyEntitiesOnTile, DAT_EntityState::ptr)(tile); + + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, baseY); + int const organism = this->OrganismLayer[tile]; + if (organism != 0) { + if (organism >= countof(DAT_LandscapeState::instance.trees)) { + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeRock, DAT_LandscapeState::ptr)( + organism - countof(DAT_LandscapeState::instance.trees)); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(8, x, y); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeTree, DAT_LandscapeState::ptr)(organism); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updateWalkAndPathLayer, + DAT_PathFindingState::ptr)(3, x, y); + } + DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = 1; + } + } + + y = baseY; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, baseY); + int const brushY = y; + this->placementOnWall = 0; + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::validateBuildingPlacementAtTile, this)(0, x, brushY); + if (this->buildingPlacementFail != FALSE) { + continue; + } + if (this->placementOnWall == 0) { + int const targetID = this->cursorTargetID; + if (targetID == -1) { + continue; + } + int const owner = DAT_BuildingsState::instance.buildings[targetID].owner; + if (targetID + == DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id + && DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id + != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuildingAndLinkedDuplicates, + DAT_BuildingsState::ptr)(DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_STOCKPILE] + .id); + } + if (DAT_BuildingsState::instance.buildings[targetID].buildingType + == OpenSHC::Map::Buildings::BT_STOCKPILE + && DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id + != 0) { + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuildingAndLinkedDuplicates, + DAT_BuildingsState::ptr)(DAT_GameState::instance.playerDataArray[owner] + .buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP] + .id); + } + this->showNoRubbleWhenDestroyingBuilding = 1; + MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::destroyBuildingAndLinkedDuplicates, + DAT_BuildingsState::ptr)(this->cursorTargetID); + } else { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::spawnEraserTileEffect, this)( + 0, DAT_ViewportRenderState::instance.translationMatrix[brushY].addXgetTile + x); + } + } + + y = baseY; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + TRUE, index, &tile, &y, baseTile, baseY); + for (int unit = DAT_TileMapState::instance.UnitLayer[tile]; unit != 0; + unit = DAT_UnitsState::instance.units[unit].nextUnitOnTheSameTile) { + DAT_UnitsState::instance.units[unit].logicalState = OpenSHC::Map::Units::ULS_REMOVE; + } + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/useLevelBrush.cpp b/src/OpenSHC/Map/TileMapState/useLevelBrush.cpp new file mode 100644 index 0000000000..b9cf1a210d --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/useLevelBrush.cpp @@ -0,0 +1,109 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/EditorAffectType.hpp" +#include "OpenSHC/Map/TileMapState/NeighbourFlagsGlobalAsm.hpp" + +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::EAT_LAND; + using OpenSHC::Map::Enums::EAT_WATER; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + 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_RIVER; + using OpenSHC::Map::LogicHelpers::L_ROCKY; + using OpenSHC::Map::LogicHelpers::L_SEA; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + // FUNCTION: STRONGHOLDCRUSADER 0x00502110 + void TileMapState::useLevelBrush(int tile, int y, uint brush, int unused) + { + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[brush]; + int highest = 0; + int lowest = 200; + int const baseTile = tile; + int const baseY = y; + int index; + for (index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, &tile, &y, baseTile, baseY); + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) == 0) { + int const height = this->HeightLayer[tile]; + if (height > highest) { + highest = height; + } + if (height < lowest) { + lowest = height; + } + } + } + + int const average = (lowest + highest) / 2; + tile = baseTile; + y = baseY; + for (index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, &tile, &y, baseTile, baseY); + int const brushTile = tile; + uint const logic = this->LogicLayer[brushTile]; + if ((logic & (L_BORDER | L_BORDER_EDGE)) != 0) { + continue; + } + if ((logic & (L_SEA | L_MARSH)) != 0 && this->editorAffectType == EAT_LAND) { + continue; + } + if ((logic & (L_SEA | L_MARSH)) == 0 && this->editorAffectType == EAT_WATER) { + continue; + } + if ((logic & (L_WALL_OR_GATEHOUSE | L_BUILDING | L_MOAT_DUG_OR_PLANNED | L_KEEP_NON_MANOR_HOUSE | L_MOAT)) + != 0) { + continue; + } + if (this->BuildingLayer[brushTile] != 0 || (logic & L_SEA) != 0) { + continue; + } + + if ((logic & L_RIVER) != 0) { + this->HeightLayer[brushTile] += 8; + } + this->LogicLayer[brushTile] &= ~L_ROCKY; + byte& height = this->HeightLayer[brushTile]; + if (this->HeightLayer[brushTile] < average) { + height = ((average - height) / 10) + height + 1; + this->Logic2Layer[brushTile] = 0; + } else if (this->HeightLayer[brushTile] > average) { + height = height - ((height - average) / 10) - 1; + this->Logic2Layer[brushTile] = 0; + } + if (this->HeightLayer[brushTile] < 8) { + this->HeightLayer[brushTile] = 8; + } + if (this->HeightLayer[brushTile] > 156) { + this->HeightLayer[brushTile] = 156; + } + this->DefaultHeightLayer[brushTile] = height; + if ((this->LogicLayer[brushTile] & L_RIVER) != 0) { + height -= 8; + } + int const brushY = y; + this->DAT_SomeTile = brushTile; + this->DAT_SomeY = brushY; + + MACRO_MARK_CHANGED_NEIGHBOURS_GLOBAL(); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(brushY, brushTile); + } + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/useTerrainHeightBrush.cpp b/src/OpenSHC/Map/TileMapState/useTerrainHeightBrush.cpp new file mode 100644 index 0000000000..09a574fb6a --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/useTerrainHeightBrush.cpp @@ -0,0 +1,129 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/LandscapeState.func.hpp" +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Map/Enums/TerrainHeightBrushMode.hpp" +#include "OpenSHC/Map/LogicHelpers/Logic2.hpp" +#include "OpenSHC/Map/TileMapState/NeighbourFlagsGlobalAsm.hpp" + +#include "OpenSHC/Globals/DAT_LandscapeState.hpp" +#include "OpenSHC/Globals/DAT_PathFindingState.hpp" +#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" + +namespace OpenSHC { +namespace Map { + + using OpenSHC::Map::Enums::THBM_FLAT; + using OpenSHC::Map::Enums::THBM_MAXIMUM; + using OpenSHC::Map::Enums::THBM_MINIMUM; + using OpenSHC::Map::Enums::THBM_SCALE; + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_HIGH; + using OpenSHC::Map::LogicHelpers::L2_PLATEAU_MEDIUM; + using OpenSHC::Map::LogicHelpers::L_BORDER; + using OpenSHC::Map::LogicHelpers::L_BORDER_EDGE; + using OpenSHC::Map::LogicHelpers::L_BUILDING; + using OpenSHC::Map::LogicHelpers::L_DEFAULT_EARTH_OR_TEXTURE; + 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 0x00502680 + void TileMapState::useTerrainHeightBrush(int tile, int y, uint brush, TerrainHeightBrushModeShort mode) + { + int const baseTile = tile; + int const baseY = y; + int const brushSize = DAT_TerrainDefinedData::instance.BrushSizeArray[brush]; + + int highest = 0; + int lowest = 200; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, &tile, &y, baseTile, baseY); + if ((this->LogicLayer[tile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + continue; + } + if (this->HeightLayer[tile] > highest) { + highest = this->HeightLayer[tile]; + } + if (this->HeightLayer[tile] < lowest) { + lowest = this->HeightLayer[tile]; + } + } + + int const average = (lowest + highest) / 2; + tile = baseTile; + y = baseY; + for (int index = 0; index < brushSize; index++) { + MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getTileForBrush, this)( + 1, index, &tile, &y, baseTile, baseY); + int const brushTile = tile; + if ((this->LogicLayer[brushTile] & (L_BORDER | L_BORDER_EDGE)) != 0) { + continue; + } + if ((this->LogicLayer[brushTile] + & (L_SEA | L_WALL_OR_GATEHOUSE | L_BUILDING | L_KEEP_NON_MANOR_HOUSE | L_MARSH | L_MOAT)) + != 0) { + continue; + } + if (this->BuildingLayer[brushTile] != 0) { + continue; + } + + this->HeightLayer[brushTile] += 1; + byte& height = this->HeightLayer[brushTile]; + if (mode == THBM_MINIMUM) { + height = 8; + this->Logic2Layer[brushTile] &= ~(L2_PLATEAU_MEDIUM | L2_PLATEAU_HIGH); + } else if (mode == THBM_MAXIMUM) { + height = 156; + this->LogicLayer[brushTile] |= L_DEFAULT_EARTH_OR_TEXTURE; + } else if (mode == THBM_FLAT) { + height = 100; + } else if (mode == THBM_SCALE) { + int ratio = 100; + if (average != 0) { + ratio = height * 100 / average; + } + ratio = (ratio / 8 + 100) * height / 100; + if (ratio > 156) { + ratio = 156; + } + height = ratio; + } + + if ((this->LogicLayer[brushTile] & L_ROCKY) != 0) { + int const organism = this->OrganismLayer[brushTile]; + if (organism >= 2000) { + MACRO_CALL_MEMBER(OpenSHC::Map::LandscapeState_Func::removeRock, DAT_LandscapeState::ptr)( + organism - 2000); + } + } + this->LogicLayer[brushTile] &= ~L_ROCKY; + if (this->HeightLayer[brushTile] < 8) { + this->HeightLayer[brushTile] = 8; + } + if (this->HeightLayer[brushTile] > 156) { + this->HeightLayer[brushTile] = 156; + } + this->DefaultHeightLayer[brushTile] = height; + if ((this->LogicLayer[brushTile] & L_RIVER) != 0) { + this->HeightLayer[brushTile] -= 8; + } + int const brushY = y; + this->DAT_SomeTile = brushTile; + this->DAT_SomeY = brushY; + + MACRO_MARK_CHANGED_NEIGHBOURS_GLOBAL(); + MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections, + DAT_PathFindingState::ptr)(brushY, brushTile); + } + this->forceUpdateLogicalAndMiscDisplayLayers = 1; + } + +} +} diff --git a/src/OpenSHC/Map/TileMapState/validateWallBuildPath.cpp b/src/OpenSHC/Map/TileMapState/validateWallBuildPath.cpp new file mode 100644 index 0000000000..997a682296 --- /dev/null +++ b/src/OpenSHC/Map/TileMapState/validateWallBuildPath.cpp @@ -0,0 +1,284 @@ +#include "../TileMapState.func.hpp" + +#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Game/GameMode2.hpp" +#include "OpenSHC/Map/Buildings/BuildingFailReasonEnum.hpp" +#include "OpenSHC/Map/Buildings/Enums/BuildingPlacementFailState.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_LandscapeState.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::Buildings::Enums::BPFS_BLOCKED; + using OpenSHC::Map::Buildings::Enums::BPFS_NONE; + + using OpenSHC::Map::LogicHelpers::L_BORDER; + 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_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_TREE; + using OpenSHC::Map::LogicHelpers::L_TREE_VARIATION; + using OpenSHC::Map::LogicHelpers::L_WALL_OR_GATEHOUSE; + + using OpenSHC::Game::GameMode; + using OpenSHC::Game::GameMode2; + using OpenSHC::Map::Buildings::BuildingFailReasonEnum; + using OpenSHC::Map::Units::UnitType; + + // FUNCTION: STRONGHOLDCRUSADER 0x005029D0 + void TileMapState::validateWallBuildPath(int playerID, int x1, int y1, int x2, int y2, MappersEnumShort command) + { + int overshoot = 2; + int budget = 0; + int enemyRange; + int searchRange; + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + enemyRange = 15; + searchRange = 7; + } else { + enemyRange = 30; + searchRange = 30; + } + this->buildingPlacementFail = BPFS_NONE; + this->illegalBuild = TRUE; + this->field_0x554920 = 0; + if (x1 < 0 || x1 > MC_MAP_XY_LIMIT_INCLUSIVE || y1 < 0 || y1 > MC_MAP_XY_LIMIT_INCLUSIVE) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y1 * MC_MAP_XY_LIMIT + x1] == 0) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + bool const endOutsideMap = x2 < 0 || x2 > MC_MAP_XY_LIMIT_INCLUSIVE || y2 < 0 || y2 > MC_MAP_XY_LIMIT_INCLUSIVE; + if (endOutsideMap) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + if (DAT_ViewportRenderState::instance.DAT_BinaryTileMap400x400[y2 * MC_MAP_XY_LIMIT + x2] == 0) { + this->buildingPlacementFail = BPFS_BLOCKED; + return; + } + + this->DAT_SomeTile = DAT_ViewportRenderState::instance.translationMatrix[y1].addXgetTile + x1; + this->DAT_SomeY = y1; + if (command == OpenSHC::Commands::M_MAPPER_STAIR) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isTileEnclosedByWallsOrGates, this)( + this->DAT_SomeTile, y1) + == FALSE) { + return; + } + int const height = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getMaxWallHeightInBrushArea, this)( + this->DAT_SomeTile, y1); + this->maxWallHeightInPath = height; + if (height <= 16) { + return; + } + budget = height; + overshoot = 2; + } else if (command == OpenSHC::Commands::M_MAPPER_CRENAL + && MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isTileEnclosedByWalls, this)(this->DAT_SomeTile, y1) + == FALSE) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_19; + return; + } + + this->field_0x554920 = 1; + int upY = y1 - y2; + int leftX = x1 - x2; + int downY = y2 - y1; + int rightX = x2 - x1; + int x = x1; + int y = y1; + do { + int const tile = DAT_ViewportRenderState::instance.translationMatrix[y].addXgetTile + x; + uint const logic = this->LogicLayer[tile]; + if ((logic & (L_PLAIN1_AND_FARM | L_BORDER)) != 0) { + return; + } + if ((logic & (L_SEA | L_BUILDING | L_KEEP_NON_MANOR_HOUSE | L_MARSH | L_MOAT)) != 0) { + return; + } + if (this->BuildingLayer[tile] != 0) { + return; + } + if ((logic & (L_TREE | L_TREE_VARIATION)) != 0) { + int const organism = this->OrganismLayer[tile]; + if (organism != 0 && organism < 2000) { + switch (DAT_LandscapeState::instance.trees[organism].treeType) { + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_A: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_B: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_C: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_D: + case OpenSHC::Map::Trees::TT_SHRUB_NEEDLE_PALM_E: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_A: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_B: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_C: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_D: + case OpenSHC::Map::Trees::TT_SHRUB_PYGMY_E: + case OpenSHC::Map::Trees::TT_SHRUB_PIPE_CACTUS: + case OpenSHC::Map::Trees::TT_SHRUB_SUCCULENT: + case OpenSHC::Map::Trees::TT_SHRUB_CYCAD: + case OpenSHC::Map::Trees::TT_SHRUB_PRICKLYPEAR: + break; + default: + return; + } + } + } + if ((logic & (L_RIVER | L_FORD)) != 0) { + return; + } + if ((logic & L_ROCKY) != 0) { + return; + } + if (this->UnitLayer[tile] != 0 && (logic & L_WALL_OR_GATEHOUSE) == 0 + && DAT_UnitsState::instance.units[this->UnitLayer[tile]].unitType != OpenSHC::Map::Units::UT_CHICKEN) { + return; + } + if (DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_EDITOR + && DAT_GameCore::instance.gameMode_2 != OpenSHC::Game::GM_SIEGE_THAT + && MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isEnemyTooCloseUnk, + DAT_PathFindingState::ptr)(playerID, x, y, enemyRange) + != FALSE) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + return; + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isOpponentBuildingInRange, + DAT_PathFindingState::ptr)(playerID, x, y, searchRange, -1, -1, -1) + != FALSE) { + if (this->buildingPlacementFailReason == OpenSHC::Map::Buildings::BRE_UNKNOWN_18) { + return; + } + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_19; + return; + } + if (DAT_GameSynchronyState::instance.currentGameMode != OpenSHC::Game::GM_SOLITARY) { + int buildRange + = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::getCastleBuildRangeForMapSize, this)(); + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isTileInRangeOfKeepRange, + DAT_PathFindingState::ptr)(playerID, x, y, buildRange) + != FALSE) { + if (this->buildingPlacementFailReason == OpenSHC::Map::Buildings::BRE_UNKNOWN_18) { + return; + } + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_19; + return; + } + } + } + if (DAT_GameCore::instance.gameMode_2 == OpenSHC::Game::GM_EDITOR + && MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isOpponentBuildingInRange, + DAT_PathFindingState::ptr)(playerID, x, y, 7, -1, -1, -1) + != FALSE) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::findSomeSuitableLocationUnk, + DAT_PathFindingState::ptr)(playerID, x, y, 2) + != FALSE) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_17; + return; + } + if (MACRO_CALL_MEMBER(OpenSHC::Map::Navigation::PathFindingState_Func::isSignPostWithinDistance, + DAT_PathFindingState::ptr)(x, y, DAT_GameState::instance.mapAndTime.unk_signpostDistance + 5) + != FALSE) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_21; + return; + } + if (command == OpenSHC::Commands::M_MAPPER_CRENAL) { + if (MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::isTileEnclosedByWalls, this)(tile, y) == FALSE) { + this->buildingPlacementFailReason = OpenSHC::Map::Buildings::BRE_UNKNOWN_19; + return; + } + } else if (command == OpenSHC::Commands::M_MAPPER_STAIR + && (budget <= 16 || (this->LogicLayer[tile] & L_WALL_OR_GATEHOUSE) != 0)) { + break; + } + + int stepX = leftX; + if (x < x2) { + stepX = rightX; + } + int stepY = upY; + if (y < y2) { + stepY = downY; + } + if (command == OpenSHC::Commands::M_MAPPER_STAIR) { + if (stepX > stepY) { + if (x >= x2) { + leftX -= 1; + x -= 1; + rightX += 1; + } else { + leftX += 1; + x += 1; + rightX -= 1; + } + } else if (stepY > 0) { + if (y >= y2) { + y -= 1; + upY -= 1; + downY += 1; + } else { + y += 1; + upY += 1; + downY -= 1; + } + } else { + overshoot -= 1; + } + } else { + if (stepX != 0) { + if (x >= x2) { + leftX -= 1; + x -= 1; + rightX += 1; + } else { + leftX += 1; + x += 1; + rightX -= 1; + } + } + if (stepY != 0) { + if (y >= y2) { + y -= 1; + upY -= 1; + downY += 1; + } else { + y += 1; + upY += 1; + downY -= 1; + } + } + if (x == x2 && y == y2) { + overshoot -= 1; + } + } + if (budget > 16) { + budget -= 16; + } + } while (x != x2 || y != y2 || overshoot != 0); + this->illegalBuild = FALSE; + } + +} +} diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index 47b2ecfdf6..4051e4292d 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -38741,7 +38741,7 @@ SHC_3BB0A8C1_0x004F6A80 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F6AE0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F6B20 | 0.0% | Pending +SHC_3BB0A8C1_0x004F6B20 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F6C20 | 0.0% | Pending @@ -38761,7 +38761,7 @@ SHC_3BB0A8C1_0x004F70D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F70E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F70F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F70F0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F7140 | 0.0% | Pending @@ -38769,7 +38769,7 @@ SHC_3BB0A8C1_0x004F7170 | 0.0% | Pending SHC_3BB0A8C1_0x004F79D0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F7A80 | 0.0% | Pending +SHC_3BB0A8C1_0x004F7A80 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F7E50 | 0.0% | Pending @@ -39377,9 +39377,9 @@ SHC_3BB0A8C1_0x004F8AC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F8B50 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F8BD0 | 0.0% | Pending +SHC_3BB0A8C1_0x004F8BD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F9000 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9000 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F9220 | 100.0% | Reimplemented @@ -39387,7 +39387,7 @@ SHC_3BB0A8C1_0x004F93E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F94A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004F9590 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9590 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F9630 | 0.0% | Pending @@ -39413,7 +39413,7 @@ SHC_3BB0A8C1_0x004F9980 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F99D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004F9A60 | 0.0% | Pending +SHC_3BB0A8C1_0x004F9A60 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F9D64 | 0.0% | Pending @@ -39653,9 +39653,9 @@ SHC_3BB0A8C1_0x004F9DF0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004F9F00 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FA000 | 0.0% | Pending +SHC_3BB0A8C1_0x004FA000 | 68.7% | Asm differs: register and stack slot assignment; wall and wallTileCount are volatile -SHC_3BB0A8C1_0x004FA2D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FA2D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FA460 | 100.0% | Reimplemented @@ -40343,7 +40343,7 @@ SHC_3BB0A8C1_0x004FA759 | 0.0% | Pending SHC_3BB0A8C1_0x004FA75A | 0.0% | Pending -SHC_3BB0A8C1_0x004FA760 | 0.0% | Pending +SHC_3BB0A8C1_0x004FA760 | 98.6% | Instruction selection differs: playerID - 40 is a lea in the original, a sub in ours SHC_3BB0A8C1_0x004FA8D0 | 0.0% | Pending @@ -40365,11 +40365,11 @@ SHC_3BB0A8C1_0x004FAD70 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FAE50 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FAEE0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FAEE0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FAF70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FB0C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB0C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FB2E0 | 0.0% | Pending @@ -40567,21 +40567,21 @@ SHC_3BB0A8C1_0x004FB358 | 0.0% | Pending SHC_3BB0A8C1_0x004FB360 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FB3F0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB3F0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FB4D0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB4D0 | 93.5% | Asm differs: an extra movzx and one register choice; kind is read through volatile SHC_3BB0A8C1_0x004FB770 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FB7D0 | 0.0% | Pending -SHC_3BB0A8C1_0x004FB8E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB8E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FB970 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB970 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FB990 | 0.0% | Pending -SHC_3BB0A8C1_0x004FB9E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FB9E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FBC30 | 100.0% | Reimplemented @@ -41079,15 +41079,15 @@ SHC_3BB0A8C1_0x004FBD70 | 0.0% | Pending SHC_3BB0A8C1_0x004FBD80 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FBE70 | 0.0% | Pending +SHC_3BB0A8C1_0x004FBE70 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FC0B0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC0B0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FC280 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC280 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FC340 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FC490 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC490 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FC650 | 100.0% | Reimplemented @@ -41095,17 +41095,17 @@ SHC_3BB0A8C1_0x004FC7C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FC810 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FC9E0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FC9E0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FDB00 | 0.0% | Pending +SHC_3BB0A8C1_0x004FDB00 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FF080 | 0.0% | Pending +SHC_3BB0A8C1_0x004FF080 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FF420 | 0.0% | Pending -SHC_3BB0A8C1_0x004FF870 | 0.0% | Pending +SHC_3BB0A8C1_0x004FF870 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FF990 | 0.0% | Pending +SHC_3BB0A8C1_0x004FF990 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FFAAC | 0.0% | Pending @@ -41261,7 +41261,7 @@ SHC_3BB0A8C1_0x004FFB03 | 0.0% | Pending SHC_3BB0A8C1_0x004FFB10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004FFBA0 | 0.0% | Pending +SHC_3BB0A8C1_0x004FFBA0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004FFECC | 0.0% | Pending @@ -41437,7 +41437,7 @@ SHC_3BB0A8C1_0x00500310 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500370 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005003D0 | 0.0% | Pending +SHC_3BB0A8C1_0x005003D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00500500 | 100.0% | Reimplemented @@ -41541,7 +41541,7 @@ SHC_3BB0A8C1_0x00501760 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005017A0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005017C0 | 0.0% | Pending +SHC_3BB0A8C1_0x005017C0 | 95.0% | 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on SHC_3BB0A8C1_0x00501A20 | 100.0% | Reimplemented @@ -41563,23 +41563,23 @@ SHC_3BB0A8C1_0x00501CC8 | 0.0% | Pending SHC_3BB0A8C1_0x00501CD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00501D90 | 0.0% | Pending +SHC_3BB0A8C1_0x00501D90 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00501F50 | 0.0% | Pending +SHC_3BB0A8C1_0x00501F50 | 83.9% | 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on SHC_3BB0A8C1_0x00501FE0 | 0.0% | Pending -SHC_3BB0A8C1_0x00502110 | 0.0% | Pending +SHC_3BB0A8C1_0x00502110 | 53.0% | 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on -SHC_3BB0A8C1_0x00502390 | 0.0% | Pending +SHC_3BB0A8C1_0x00502390 | 29.9% | 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on -SHC_3BB0A8C1_0x005024F0 | 0.0% | Pending +SHC_3BB0A8C1_0x005024F0 | 61.6% | 100.0 with OPENSHC_FUNCTION_VISIBILITY_UNITS on -SHC_3BB0A8C1_0x00502680 | 0.0% | Pending +SHC_3BB0A8C1_0x00502680 | 62.7% | 76.4 with OPENSHC_FUNCTION_VISIBILITY_UNITS on, asm differs SHC_3BB0A8C1_0x00502950 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005029D0 | 0.0% | Pending +SHC_3BB0A8C1_0x005029D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00502F14 | 0.0% | Pending @@ -41615,7 +41615,7 @@ SHC_3BB0A8C1_0x00502F29 | 0.0% | Pending SHC_3BB0A8C1_0x00502F2A | 0.0% | Pending -SHC_3BB0A8C1_0x00502F30 | 0.0% | Pending +SHC_3BB0A8C1_0x00502F30 | 100.0% | Reimplemented SHC_3BB0A8C1_0x0050347C | 0.0% | Pending @@ -41655,7 +41655,7 @@ SHC_3BB0A8C1_0x005034A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00503720 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005037B0 | 0.0% | Pending +SHC_3BB0A8C1_0x005037B0 | 97.3% | Register allocation differs, two stack slots swapped SHC_3BB0A8C1_0x005046A0 | 0.0% | Pending @@ -41959,7 +41959,7 @@ SHC_3BB0A8C1_0x00504A26 | 0.0% | Pending SHC_3BB0A8C1_0x00504A27 | 0.0% | Pending -SHC_3BB0A8C1_0x00504A30 | 0.0% | Pending +SHC_3BB0A8C1_0x00504A30 | 94.2% | Asm differs: ebp is saved at a different point and the bounds checks are scheduled differently SHC_3BB0A8C1_0x00504E88 | 0.0% | Pending @@ -42069,7 +42069,7 @@ SHC_3BB0A8C1_0x00504ED1 | 0.0% | Pending SHC_3BB0A8C1_0x00504EE0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00504F10 | 0.0% | Pending +SHC_3BB0A8C1_0x00504F10 | 78.0% | Asm differs: 0x14-byte stack frame instead of 0x18, stack slots assigned differently SHC_3BB0A8C1_0x005050F0 | 0.0% | Pending @@ -42081,23 +42081,23 @@ SHC_3BB0A8C1_0x00505A10 | 0.0% | Pending SHC_3BB0A8C1_0x005060C0 | 0.0% | Pending -SHC_3BB0A8C1_0x00506370 | 0.0% | Pending +SHC_3BB0A8C1_0x00506370 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00506AD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00506BD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00506BD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00506D40 | 0.0% | Pending +SHC_3BB0A8C1_0x00506D40 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00506E10 | 0.0% | Pending +SHC_3BB0A8C1_0x00506E10 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00506F40 | 0.0% | Pending +SHC_3BB0A8C1_0x00506F40 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00507060 | 0.0% | Pending +SHC_3BB0A8C1_0x00507060 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00507130 | 0.0% | Pending +SHC_3BB0A8C1_0x00507130 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00507280 | 0.0% | Pending +SHC_3BB0A8C1_0x00507280 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00507350 | 100.0% | Reimplemented @@ -42135,37 +42135,37 @@ SHC_3BB0A8C1_0x0050741D | 0.0% | Pending SHC_3BB0A8C1_0x0050741E | 0.0% | Pending -SHC_3BB0A8C1_0x00507420 | 0.0% | Pending +SHC_3BB0A8C1_0x00507420 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00507560 | 0.0% | Pending +SHC_3BB0A8C1_0x00507560 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005076A0 | 0.0% | Pending +SHC_3BB0A8C1_0x005076A0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00507830 | 0.0% | Pending -SHC_3BB0A8C1_0x00507BD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00507BD0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00507D50 | 0.0% | Pending -SHC_3BB0A8C1_0x00507E00 | 0.0% | Pending +SHC_3BB0A8C1_0x00507E00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00507F80 | 0.0% | Pending -SHC_3BB0A8C1_0x00508030 | 0.0% | Pending +SHC_3BB0A8C1_0x00508030 | 98.0% | Register allocation differs -SHC_3BB0A8C1_0x00508250 | 0.0% | Pending +SHC_3BB0A8C1_0x00508250 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00508540 | 0.0% | Pending +SHC_3BB0A8C1_0x00508540 | 99.3% | Asm differs: one loop ends on jne instead of jl SHC_3BB0A8C1_0x00508590 | 0.0% | Pending -SHC_3BB0A8C1_0x00508760 | 0.0% | Pending +SHC_3BB0A8C1_0x00508760 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00508870 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00508910 | 0.0% | Pending +SHC_3BB0A8C1_0x00508910 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00508A00 | 0.0% | Pending +SHC_3BB0A8C1_0x00508A00 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00508C7C | 0.0% | Pending @@ -42763,9 +42763,9 @@ SHC_3BB0A8C1_0x00508DC2 | 0.0% | Pending SHC_3BB0A8C1_0x00508DC3 | 0.0% | Pending -SHC_3BB0A8C1_0x00508DD0 | 0.0% | Pending +SHC_3BB0A8C1_0x00508DD0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00508EC0 | 0.0% | Pending +SHC_3BB0A8C1_0x00508EC0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00509180 | 0.0% | Pending @@ -44177,7 +44177,7 @@ SHC_3BB0A8C1_0x00511020 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005110B0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005111D0 | 0.0% | Pending +SHC_3BB0A8C1_0x005111D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00511240 | 0.0% | Pending @@ -44187,7 +44187,7 @@ SHC_3BB0A8C1_0x005114C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005115C0 | 0.0% | Pending -SHC_3BB0A8C1_0x005116E0 | 0.0% | Pending +SHC_3BB0A8C1_0x005116E0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00511850 | 100.0% | Reimplemented @@ -44733,7 +44733,7 @@ SHC_3BB0A8C1_0x00512100 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00512180 | 0.0% | Pending -SHC_3BB0A8C1_0x00512450 | 0.0% | Pending +SHC_3BB0A8C1_0x00512450 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005127B0 | 100.0% | Reimplemented @@ -44741,43 +44741,43 @@ SHC_3BB0A8C1_0x005127D0 | 0.0% | Pending SHC_3BB0A8C1_0x00512920 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00512940 | 0.0% | Pending +SHC_3BB0A8C1_0x00512940 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00514480 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00514520 | 0.0% | Pending +SHC_3BB0A8C1_0x00514520 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005146D0 | 0.0% | Pending +SHC_3BB0A8C1_0x005146D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00514BC0 | 0.0% | Pending -SHC_3BB0A8C1_0x00514DE0 | 0.0% | Pending +SHC_3BB0A8C1_0x00514DE0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00514F30 | 0.0% | Pending +SHC_3BB0A8C1_0x00514F30 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005151C0 | 0.0% | Pending +SHC_3BB0A8C1_0x005151C0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00515250 | 0.0% | Pending -SHC_3BB0A8C1_0x005154D0 | 0.0% | Pending +SHC_3BB0A8C1_0x005154D0 | 100.0% | Reimplemented SHC_3BB0A8C1_0x005155E0 | 0.0% | Pending SHC_3BB0A8C1_0x00515680 | 0.0% | Pending -SHC_3BB0A8C1_0x00515740 | 0.0% | Pending +SHC_3BB0A8C1_0x00515740 | 100.0% | Reimplemented SHC_3BB0A8C1_0x00515A20 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00515C80 | 0.0% | Pending +SHC_3BB0A8C1_0x00515C80 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x00515DA0 | 0.0% | Pending +SHC_3BB0A8C1_0x00515DA0 | 98.1% | Instruction scheduling differs: one stack store comes before a test instead of after SHC_3BB0A8C1_0x00515F40 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005160C0 | 0.0% | Pending +SHC_3BB0A8C1_0x005160C0 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x005162D0 | 0.0% | Pending +SHC_3BB0A8C1_0x005162D0 | 97.3% | Style pass, asm differs SHC_3BB0A8C1_0x00516A64 | 0.0% | Pending @@ -45133,7 +45133,7 @@ SHC_3BB0A8C1_0x00516B73 | 0.0% | Pending SHC_3BB0A8C1_0x00516B74 | 0.0% | Pending -SHC_3BB0A8C1_0x00516B80 | 0.0% | Pending +SHC_3BB0A8C1_0x00516B80 | 89.5% | Asm differs: tail merge and stack slots; destroyed is volatile SHC_3BB0A8C1_0x005176C8 | 0.0% | Pending @@ -45435,7 +45435,7 @@ SHC_3BB0A8C1_0x00517789 | 0.0% | Pending SHC_3BB0A8C1_0x0051778A | 0.0% | Pending -SHC_3BB0A8C1_0x00517790 | 0.0% | Pending +SHC_3BB0A8C1_0x00517790 | 99.9% | Instruction scheduling differs: one byte store is placed later SHC_3BB0A8C1_0x00518068 | 0.0% | Pending