diff --git a/src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp b/src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp new file mode 100644 index 0000000000..c8ddf9719f --- /dev/null +++ b/src/OpenSHC/UI/Enums/MinimapDrawFlags.hpp @@ -0,0 +1,25 @@ +/** + THIS FILE IS AUTO GENERATED + Communicate changes to the dev team (e.g. via a Pull Request). + Changes get lost otherwise. + + path: 'OpenSHC/UI/Enums/MinimapDrawFlags.hpp' +*/ + +#pragma once + +namespace OpenSHC { +namespace UI { + namespace Enums { + typedef enum MinimapDrawFlags { + + MDF_CENTER_ON_OFFSETS = 1, // 0x00000001 + MDF_VIEWPORT_BOX = 2, // 0x00000002 + MDF_HALF_SIZE = 4 // 0x00000004 + + } MinimapDrawFlags; + + static_assert_cpp98_obj(sizeof(MinimapDrawFlags) == 4, MinimapDrawFlags); + } // namespace Enums +} // namespace UI +} // namespace OpenSHC diff --git a/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp b/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp index 154ee9ec64..980efff798 100644 --- a/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp +++ b/src/OpenSHC/UI/MiniMap/MiniMapDefinedData.hpp @@ -41,75 +41,7 @@ namespace UI { ushort ScrubMinimapColors[8]; // 0x00000164 length: 16 ushort ThickScrubMinimapColors[8]; // 0x00000174 length: 16 ushort OasisGrassMinimapColors[52]; // 0x00000184 length: 104 - ushort PlayerColorColors[2][2]; // 0x000001EC length: 8 - ushort AnimalMinimapColour_RGB15; // 0x000001F4 length: 2 - ushort AnimalMinimapColour_RGB16; // 0x000001F6 length: 2 - ushort field_0x1f8; // 0x000001F8 length: 2 - ushort field_0x1fa; // 0x000001FA length: 2 - ushort PlayerColorColors_entry2; // 0x000001FC length: 2 - ushort field_0x1fe; // 0x000001FE length: 2 - ushort field_0x200; // 0x00000200 length: 2 - ushort field_0x202; // 0x00000202 length: 2 - ushort field_0x204; // 0x00000204 length: 2 - ushort field_0x206; // 0x00000206 length: 2 - ushort field_0x208; // 0x00000208 length: 2 - ushort field_0x20a; // 0x0000020A length: 2 - ushort field_0x20c; // 0x0000020C length: 2 - ushort field_0x20e; // 0x0000020E length: 2 - ushort field_0x210; // 0x00000210 length: 2 - ushort field_0x212; // 0x00000212 length: 2 - ushort field_0x214; // 0x00000214 length: 2 - ushort field_0x216; // 0x00000216 length: 2 - ushort field_0x218; // 0x00000218 length: 2 - ushort field_0x21a; // 0x0000021A length: 2 - ushort field_0x21c; // 0x0000021C length: 2 - ushort field_0x21e; // 0x0000021E length: 2 - ushort field_0x220; // 0x00000220 length: 2 - ushort field_0x222; // 0x00000222 length: 2 - ushort field_0x224; // 0x00000224 length: 2 - ushort field_0x226; // 0x00000226 length: 2 - ushort field_0x228; // 0x00000228 length: 2 - ushort field_0x22a; // 0x0000022A length: 2 - ushort field_0x22c; // 0x0000022C length: 2 - ushort field_0x22e; // 0x0000022E length: 2 - ushort field_0x230; // 0x00000230 length: 2 - ushort field_0x232; // 0x00000232 length: 2 - ushort field_0x234; // 0x00000234 length: 2 - ushort field_0x236; // 0x00000236 length: 2 - ushort field_0x238; // 0x00000238 length: 2 - ushort field_0x23a; // 0x0000023A length: 2 - ushort field_0x23c; // 0x0000023C length: 2 - ushort field_0x23e; // 0x0000023E length: 2 - ushort field_0x240; // 0x00000240 length: 2 - ushort field_0x242; // 0x00000242 length: 2 - ushort field_0x244; // 0x00000244 length: 2 - ushort field_0x246; // 0x00000246 length: 2 - ushort field_0x248; // 0x00000248 length: 2 - ushort field_0x24a; // 0x0000024A length: 2 - ushort field_0x24c; // 0x0000024C length: 2 - ushort field_0x24e; // 0x0000024E length: 2 - ushort field_0x250; // 0x00000250 length: 2 - ushort field_0x252; // 0x00000252 length: 2 - ushort field_0x254; // 0x00000254 length: 2 - ushort field_0x256; // 0x00000256 length: 2 - ushort field_0x258; // 0x00000258 length: 2 - ushort field_0x25a; // 0x0000025A length: 2 - ushort field_0x25c; // 0x0000025C length: 2 - ushort field_0x25e; // 0x0000025E length: 2 - ushort field_0x260; // 0x00000260 length: 2 - ushort field_0x262; // 0x00000262 length: 2 - ushort field_0x264; // 0x00000264 length: 2 - ushort field_0x266; // 0x00000266 length: 2 - ushort field_0x268; // 0x00000268 length: 2 - ushort field_0x26a; // 0x0000026A length: 2 - ushort field_0x26c; // 0x0000026C length: 2 - ushort field_0x26e; // 0x0000026E length: 2 - ushort field_0x270; // 0x00000270 length: 2 - ushort field_0x272; // 0x00000272 length: 2 - ushort field_0x274; // 0x00000274 length: 2 - ushort field_0x276; // 0x00000276 length: 2 - ushort field_0x278; // 0x00000278 length: 2 - ushort field_0x27a; // 0x0000027A length: 2 + ushort PlayerColorColors[9][4][2]; // 0x000001EC length: 144 MapColorRelatedStructure1 MinimapColorByLogicBit[8]; // 0x0000027C length: 64 int cachedKeepEnclosed; // 0x000002BC length: 4 int cachedMapOrientation; // 0x000002C0 length: 4 diff --git a/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp new file mode 100644 index 0000000000..e83ab13f75 --- /dev/null +++ b/src/OpenSHC/UI/MinimapViewState/drawMinimap.cpp @@ -0,0 +1,572 @@ +#include "../MinimapViewState.func.hpp" + +#include "OpenSHC/Map/TileMapState.func.hpp" +#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp" +#include "OpenSHC/Game/GameMode.hpp" +#include "OpenSHC/Map/Enums/MapOrientation.hpp" +#include "OpenSHC/Map/MapConstants.hpp" +#include "OpenSHC/Map/Units/States/UnitState.hpp" +#include "OpenSHC/Map/Units/UnitType.hpp" +#include "OpenSHC/Rendering/ColorMode.hpp" +#include "OpenSHC/Rendering/Enums/ViewportConstants.hpp" +#include "OpenSHC/UI/Enums/MinimapConstants.hpp" +#include "OpenSHC/UI/Enums/MinimapDrawFlags.hpp" +#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp" + +#include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp" +#include "OpenSHC/Globals/DAT_GameCore.hpp" +#include "OpenSHC/Globals/DAT_GameState.hpp" +#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp" +#include "OpenSHC/Globals/DAT_MiniMapDefinedData.hpp" +#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp" +#include "OpenSHC/Globals/DAT_TileMapState.hpp" +#include "OpenSHC/Globals/DAT_UnitsState.hpp" +#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp" +#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp" + +namespace OpenSHC { +namespace UI { + + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_LONG_ROW; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_SHORT_ROW; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_SIZE; + using OpenSHC::Rendering::Enums::VC_SCREEN_POINT_TABLE_START; + using OpenSHC::UI::Enums::MDF_CENTER_ON_OFFSETS; + using OpenSHC::UI::Enums::MDF_HALF_SIZE; + using OpenSHC::UI::Enums::MDF_VIEWPORT_BOX; + using OpenSHC::WindowsHelper::Enums::BOOLEnum; + + // A row of the minimap picture (200 pixels) in bytes, named here for the assembly (it cannot name a qualified one). + using OpenSHC::UI::Enums::MMC_BUFFER_ROW_BYTES; + + // Draws the minimap: the terrain picture, every unit as a dot in its player's colour, and the viewport's box. + // FUNCTION: STRONGHOLDCRUSADER 0x004B66C0 + void MinimapViewState::drawMinimap(int xPos, int yPos, int width, int height, uint flags, int xOffset, int yOffset, + int widthFactor, int heightFactor, int intoPreview) + { + // in this order (in another order the first stores move; found by a search over the orders) + BOOLEnum isRGB565 = FALSE; + int rowBase = VC_SCREEN_POINT_TABLE_START; + int scale = 1; + int blitWidth = width; + int blitHeight = height; + ushort* const buffer = this->field_0x44; + int sourceColumnBase = 0; + int sourceRowBase = 0; + BOOLEnum showBox = TRUE; + int mapSize = DAT_TileMapState::instance.mapSize; + if (mapSize == 0) { + mapSize = Map::MC_MAP_SIZE_400; + } + int minX; + int minY; + int maxY; + int maxX; + int quarterMargin; + int halfMargin; + // MC_MAP_SIZE_400 - mapSize written out each time (a local for it changes the stack slots) + if (width < 200) { + quarterMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 4; + minX = quarterMargin + 1; + halfMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 2; + minY = halfMargin + 2; + maxX = (Map::MC_MAP_SIZE_400 - halfMargin) / 2 - 2; + maxY = Map::MC_MAP_SIZE_400 - halfMargin; + } else { + quarterMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 4; + halfMargin = (Map::MC_MAP_SIZE_400 - mapSize) / 2; + minX = quarterMargin; + minY = halfMargin; + maxX = (Map::MC_MAP_SIZE_400 - halfMargin) / 2; + maxY = Map::MC_MAP_SIZE_400 - halfMargin; + } + if (DAT_MiniMapDefinedData::instance.cachedMapOrientation != DAT_TileMapState::instance.mapOrientation) { + MACRO_CALL_MEMBER(MinimapViewState_Func::setTileColorsDependingOnMapSize, this)(0, 100); + MACRO_CALL_MEMBER(MinimapViewState_Func::setMapPropertyDependingOnMapSize, this)(0, 100); + DAT_MiniMapDefinedData::instance.cachedMapOrientation = DAT_TileMapState::instance.mapOrientation; + } + if (this->field_0x38 != 0) { + if (this->field_0x34 == 0) { + MACRO_CALL_MEMBER(MinimapViewState_Func::setTileColorsDependingOnMapSize, this)(this->field_0x34, 2); + MACRO_CALL_MEMBER(MinimapViewState_Func::setMapPropertyDependingOnMapSize, this)(this->field_0x34, 2); + MACRO_CALL_MEMBER(Map::TileMapState_Func::collectCliffEdgeTilesForClimbData, DAT_TileMapState::ptr)(); + this->field_0x34 += 2; + } else { + MACRO_CALL_MEMBER(MinimapViewState_Func::setTileColorsDependingOnMapSize, this)(this->field_0x34, 2); + MACRO_CALL_MEMBER(MinimapViewState_Func::setMapPropertyDependingOnMapSize, this)(this->field_0x34, 2); + this->field_0x34 += 2; + // (int): the original compares signed (the header has undefined4) + if ((int)this->field_0x34 >= 100) { + --this->field_0x38; + if ((int)this->field_0x38 > 0) { + this->field_0x34 = 0; + } else { + this->field_0x38 = 0; + } + } + } + } + if (flags & MDF_HALF_SIZE) { + scale = 2; + } + // a small map sits in the middle of the 400 by 400 picture + if (DAT_TileMapState::instance.mapSize <= Map::MC_MAP_SIZE_200) { + sourceColumnBase = (Map::MC_MAP_XY_LIMIT - Map::MC_MAP_SIZE_200) / 2; + sourceRowBase = (Map::MC_MAP_XY_LIMIT - Map::MC_MAP_SIZE_200) / 2; + } + this->width = width; + this->height = height; + this->widthFactor = widthFactor; + this->heightFactor = heightFactor; + this->x = xPos; + this->y = yPos; + this->oneOrTwo = scale; + int const viewWidth = DAT_ViewportRenderState::instance.viewportState.viewportHeight - 5; + int boxWidth = viewWidth * widthFactor / scale + widthFactor / scale - 1; + int boxHeight = DAT_ViewportRenderState::instance.viewportState.viewportWidth * heightFactor / scale - 1; + // width and height count tiles from here on, as in the original, which keeps the counts in their stack slots + width = width / widthFactor * scale; + height = height / heightFactor * scale; + if (DAT_WindowAndDirectDraw::instance.colorBitMode == OpenSHC::Rendering::RGB_565) { + isRGB565 = TRUE; + } + int boxX = xOffset; + int boxY = yOffset; + int const half = mapSize / 2; + if (half < width) { + xOffset = quarterMargin - (width - half) / 2; + yOffset = halfMargin - (height - mapSize) / 2; + boxX -= viewWidth / 2; + boxY -= DAT_ViewportRenderState::instance.viewportState.viewportWidth / 2; + if (boxX < minX) { + boxWidth = half * widthFactor / scale; + boxX = minX; + showBox = FALSE; + } + if (boxY < minY) { + boxHeight = mapSize * heightFactor / scale; + boxY = minY; + showBox = FALSE; + } + } else { + if (flags & MDF_CENTER_ON_OFFSETS) { + xOffset -= width / 2; + yOffset -= height / 2; + boxX -= viewWidth / 2; + boxY -= DAT_ViewportRenderState::instance.viewportState.viewportWidth / 2; + } + if (xOffset < minX) { + xOffset = minX; + } else if (xOffset > maxX - width) { + xOffset = maxX - width; + } + if (yOffset < minY) { + yOffset = minY; + } else if (yOffset > maxY - height - 1) { + yOffset = maxY - height - 1; + } + if (boxX < minX) { + boxX = minX; + } else if (boxX > maxX - DAT_ViewportRenderState::instance.viewportState.viewportHeight + 5) { + boxX = maxX - DAT_ViewportRenderState::instance.viewportState.viewportHeight + 5; + } + if (boxY < minY) { + boxY = minY; + } else if (boxY > maxY - DAT_ViewportRenderState::instance.viewportState.viewportWidth - 1) { + boxY = maxY - DAT_ViewportRenderState::instance.viewportState.viewportWidth - 1; + } + } + boxX = (boxX - xOffset) * widthFactor / scale + xPos; + this->tileOffsetY = yOffset; + this->tileOffsetX = xOffset; + boxY = (boxY - yOffset) * heightFactor / scale + yPos; + int const halfY = yOffset / 2; + int const viewportHeight = DAT_ViewportRenderState::instance.viewportState.viewportHeight; + int const otherParity = viewportHeight + 1; + int rowParity = otherParity; + if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_NORTH) { + rowBase = VC_SCREEN_POINT_TABLE_START; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_WEST) { + rowBase = VC_SCREEN_POINT_TABLE_START + VC_SCREEN_POINT_TABLE_SIZE; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_SOUTH) { + rowBase = VC_SCREEN_POINT_TABLE_START + 2 * VC_SCREEN_POINT_TABLE_SIZE; + } else if (DAT_TileMapState::instance.mapOrientation == Map::Enums::MO_EAST) { + rowBase = VC_SCREEN_POINT_TABLE_START + 3 * VC_SCREEN_POINT_TABLE_SIZE; + } + int sourceX = xOffset * widthFactor / scale; + int const sourceY = halfY * heightFactor; + rowBase += halfY * (VC_SCREEN_POINT_SHORT_ROW + VC_SCREEN_POINT_LONG_ROW) + xOffset + 1; + // the loaded map's preview, or the screen + if (intoPreview > 0) { + DAT_PencilRenderCore::instance.surfacePtr = (ushort*)this->loadedMiniMap; + DAT_PencilRenderCore::instance.horizontalByteSize = sizeof(this->loadedMiniMap[0]); + this->someMiniMapCounterTill4 = 0; + } else { + MACRO_CALL_MEMBER(Rendering::PencilRenderCore_Func::setupPencilSurface, DAT_PencilRenderCore::ptr)(); + } + if (intoPreview != 0) { + if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_160) { + blitWidth -= 5; + xPos += 3; + } else if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_200) { + xPos += 3; + ++sourceX; + blitWidth -= 4; + } + } + // handwritten in the original: the minimap picture copied to the surface row by row + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, xPos + add eax, eax + add edi, eax + mov eax, yPos + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov esi, buffer + mov eax, sourceX + sub eax, sourceColumnBase + add eax, eax + add esi, eax + mov eax, sourceY + sub eax, sourceRowBase + mov edx, MMC_BUFFER_ROW_BYTES + mul edx + add esi, eax + mov edx, blitHeight + next_row: + mov ecx, blitWidth + mov ebx, 0 + next_pixel: + mov ax, word ptr [esi + ebx] + mov word ptr [edi + ebx], ax + add ebx, 2 + dec ecx + jne next_pixel + add esi, MMC_BUFFER_ROW_BYTES + add edi, DAT_PencilRenderCore::instance.horizontalByteSize + dec edx + jne next_row + } + // 160 keeps its shift and 200 keeps one of its three pixels (the original tests 160 first) + if (intoPreview != 0) + { + if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_160) { + } else if (DAT_TileMapState::instance.mapSize == Map::MC_MAP_SIZE_200) { + xPos -= 2; + } + } + // the colour table: per colour slot four animation frames in the two colour modes + uint color; + // declared once for both unit loops (declared in each loop they take other stack slots) + int row; + int column; + int rowLength; + int start; + int pixelX; + int pixelY; + int unit; + int baseX; + int baseY; + int offsetX; + int offsetY; + int x; + int y; + int px; + if (!DAT_GameCore::instance.altRToggleMinimapHideWildlife) { + for (row = 0; row < height; ++row, rowBase += rowLength) { + pixelY = row * heightFactor; + if (rowParity == otherParity) { + rowParity = viewportHeight; + start = widthFactor / 2; + rowLength = VC_SCREEN_POINT_SHORT_ROW; + } else { + rowParity = otherParity; + start = 0; + rowLength = VC_SCREEN_POINT_LONG_ROW; + } + if (scale != 2 || !(pixelY & 1)) { + for (column = -2; column < width; ++column) { + pixelX = column * widthFactor + start; + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[rowBase + column]]; + if (unit == 0) { + if (scale != 2) { + continue; + } + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[column + rowLength + rowBase]]; + if (unit == 0) { + continue; + } + } + short const owner = DAT_UnitsState::instance.units[unit].owner; + if (owner == 0) { + color = DAT_MiniMapDefinedData::instance.PlayerColorColors[0][2][isRGB565]; + } else { + int colorPlayer; + if (DAT_UnitsState::instance.units[unit].isSelectable_OR_matchTime != 0) { + switch (DAT_UnitsState::instance.units[unit].unitType) { + case Map::Units::UT_E_KNIGHT: + case Map::Units::UT_A_HARCHER: + colorPlayer = DAT_UnitsState::instance.units[unit].displayColorPlayerID; + break; + case Map::Units::UT_S_TOWER: + colorPlayer = owner; + break; + default: + colorPlayer = DAT_UnitsState::instance.units[unit].calculatedOwnerPlayerIndex; + break; + } + } else { + colorPlayer = owner; + } + if (colorPlayer <= 0) { + colorPlayer = 1; + } + switch (DAT_UnitsState::instance.units[unit].unitType) { + case Map::Units::UT_A_ASSASSIN: + color = DAT_MiniMapDefinedData::instance + .PlayerColorColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[colorPlayer]][0][isRGB565]; + if (DAT_GameState::instance.mapAndTime.playerTeams[owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && DAT_UnitsState::instance.units[unit].assassinsMicroDistanceToEnemyUnk > 160 + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK_WALL + && (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + || DAT_UnitsState::instance.units[unit].idleCounterUnk <= 2400)) { + continue; + } + break; + case Map::Units::UT_COW: + case Map::Units::UT_HUNTERDOG: + case Map::Units::UT_CHICKEN: + color = DAT_MiniMapDefinedData::instance.PlayerColorColors[0][2][isRGB565]; + break; + case Map::Units::UT_S_CATAPULT: + case Map::Units::UT_S_TREBUCHET: + case Map::Units::UT_S_MANGONEL: + case Map::Units::UT_S_TOWER: + case Map::Units::UT_S_BATTERINGRAM: + case Map::Units::UT_S_SHIELD: + case Map::Units::UT_S_BALLISTA: + case Map::Units::UT_S_FBALLISTA: + color = DAT_MiniMapDefinedData::instance.PlayerColorColors + [DAT_BlendingDefinedData::instance.PlayerSlotUnitColor[colorPlayer]] + [this->someMiniMapCounterTill4][isRGB565]; + break; + default: + color = DAT_MiniMapDefinedData::instance + .PlayerColorColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[colorPlayer]][0][isRGB565]; + break; + } + } + if (scale == 1) { + baseX = pixelX + xPos; + baseY = pixelY + yPos; + for (offsetX = 0; offsetX < widthFactor; ++offsetX) { + if (baseX + offsetX >= xPos && baseX + offsetX < width * widthFactor + xPos) { + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, baseX + add eax, offsetX + add eax, eax + add edi, eax + mov eax, baseY + add eax, offsetY + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } else { + // Every other pixel at half the position (a plain loop skipping odd ones loses the match). + for (offsetX = pixelX & 1; offsetX < widthFactor; offsetX += 2) { + px = pixelX + offsetX; + if (px >= 0 && px < width * widthFactor) { + x = px / scale + xPos; + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + y = (pixelY + offsetY) / scale + yPos; + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, x + add eax, eax + add edi, eax + mov eax, y + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } + } + } + } + } else { + // with the wildlife hidden: own team and enemies in two colours + uint const ownColor = DAT_MiniMapDefinedData::instance.PlayerColorColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[DAT_GameSynchronyState::instance.currentPlayerSlotID]][0][isRGB565]; + uint enemyColor = 0; + for (int player = 1; player < countof(DAT_GameState::instance.mapAndTime.playerTeams); ++player) { + if (DAT_GameState::instance.mapAndTime.playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + != DAT_GameState::instance.mapAndTime.playerTeams[player]) { + enemyColor = DAT_MiniMapDefinedData::instance.PlayerColorColors[DAT_BlendingDefinedData::instance + .PlayerSlotUnitColor[player]][0][isRGB565]; + break; + } + } + for (row = 0; row < height; ++row, rowBase += rowLength) { + pixelY = row * heightFactor; + if (rowParity == otherParity) { + rowParity = viewportHeight; + start = widthFactor / 2; + rowLength = VC_SCREEN_POINT_SHORT_ROW; + } else { + rowParity = otherParity; + start = 0; + rowLength = VC_SCREEN_POINT_LONG_ROW; + } + if (scale != 2 || !(pixelY & 1)) { + for (column = -2; column < width; ++column) { + pixelX = column * widthFactor + start; + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[rowBase + column]]; + if (unit == 0) { + if (scale != 2) { + continue; + } + unit = DAT_TileMapState::instance.UnitLayer[DAT_ViewportRenderState::instance + .screenPointToTileNumber[column + rowLength + rowBase]]; + if (unit == 0) { + continue; + } + } + short const owner = DAT_UnitsState::instance.units[unit].owner; + if (owner == 0) { + continue; + } + switch (DAT_UnitsState::instance.units[unit].unitType) { + case Map::Units::UT_COW: + case Map::Units::UT_HUNTERDOG: + case Map::Units::UT_CHICKEN: + continue; + case Map::Units::UT_A_ASSASSIN: + if (DAT_GameState::instance.mapAndTime.playerTeams[owner] + != DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + && DAT_UnitsState::instance.units[unit].assassinsMicroDistanceToEnemyUnk > 160 + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK + && DAT_UnitsState::instance.units[unit].state.generic + != Map::Units::States::US_MELEE_ATTACK_WALL + && (DAT_GameSynchronyState::instance.currentGameMode != Game::GM_SOLITARY + || DAT_UnitsState::instance.units[unit].idleCounterUnk <= 2400)) { + continue; + } + break; + default: + break; + } + if (DAT_GameState::instance.mapAndTime + .playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID] + == DAT_GameState::instance.mapAndTime.playerTeams[owner]) { + color = (ushort)ownColor; + } else { + color = (ushort)enemyColor; + } + if (scale == 1) { + baseX = pixelX + xPos; + baseY = pixelY + yPos; + for (offsetX = 0; offsetX < widthFactor; ++offsetX) { + if (baseX + offsetX >= xPos && baseX + offsetX < width * widthFactor + xPos) { + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, baseX + add eax, offsetX + add eax, eax + add edi, eax + mov eax, baseY + add eax, offsetY + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } else { + // Every other pixel at half the position (a plain loop skipping odd ones loses the match). + for (offsetX = pixelX & 1; offsetX < widthFactor; offsetX += 2) { + px = pixelX + offsetX; + if (px >= 0 && px < width * widthFactor) { + x = px / scale + xPos; + for (offsetY = 0; offsetY < heightFactor; ++offsetY) { + y = (pixelY + offsetY) / scale + yPos; + // handwritten in the original: one pixel + __asm { + mov edi, DAT_PencilRenderCore::instance.surfacePtr + mov eax, x + add eax, eax + add edi, eax + mov eax, y + mov edx, DAT_PencilRenderCore::instance.horizontalByteSize + mul edx + add edi, eax + mov ax, word ptr color + mov word ptr [edi], ax + } + } + } + } + } + } + } + } + } + if ((flags & MDF_VIEWPORT_BOX) && showBox) { + if (boxX < xPos) { + if (boxX + boxWidth >= blitWidth + xPos) { + return; + } + boxWidth += boxX - xPos; + boxX = xPos; + } else if (boxX + boxWidth >= blitWidth + xPos) { + boxWidth = blitWidth - boxX + xPos - 1; + } + if (boxY < yPos) { + if (boxY + boxHeight >= blitHeight + yPos) { + return; + } + boxHeight += boxY - yPos; + boxY = yPos; + } else if (boxY + boxHeight >= yPos + blitHeight) { + boxHeight = blitHeight - boxY + yPos; + } + MACRO_CALL_MEMBER(Rendering::PencilRenderCore_Func::drawBorderBox, DAT_PencilRenderCore::ptr)( + boxX, boxY, boxX + boxWidth, boxY + boxHeight, -1); + } + } + +} +} diff --git a/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp b/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp index 534337a3c0..4c3b4b3a6d 100644 --- a/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp +++ b/src/OpenSHC/UI/Rendering/PencilRenderCore.func.hpp @@ -79,7 +79,7 @@ namespace UI { Address::SHC_3BB0A8C1_0x004710A0, &PencilRenderCore::drawBoxWithRoundedEdges) drawBoxWithRoundedEdges; - MACRO_FUNCTION_RESOLVER(void (PencilRenderCore::*)(int, int, int, int, ushort), false, + MACRO_FUNCTION_RESOLVER(void (PencilRenderCore::*)(int, int, int, int, short), false, Address::SHC_3BB0A8C1_0x004711B0, &PencilRenderCore::drawBorderBox) drawBorderBox; diff --git a/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp b/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp index e16265999a..7062c22aeb 100644 --- a/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp +++ b/src/OpenSHC/UI/Rendering/PencilRenderCore.hpp @@ -89,7 +89,7 @@ namespace UI { void drawBoxWithRoundedEdges( int left, int top, int right, int bottom, RoundedBoxEdgeRoundingLevel roundingLevel); - void drawBorderBox(int left, int top, int right, int bottom, ushort color); + void drawBorderBox(int left, int top, int right, int bottom, short color); void drawDiagonalHeigherThanWideUnk(); diff --git a/status/addresses-SHC-3BB0A8C1.txt b/status/addresses-SHC-3BB0A8C1.txt index b358739697..ff7623ff7c 100644 --- a/status/addresses-SHC-3BB0A8C1.txt +++ b/status/addresses-SHC-3BB0A8C1.txt @@ -26919,7 +26919,7 @@ SHC_3BB0A8C1_0x004B6640 | 100.0% | Reimplemented SHC_3BB0A8C1_0x004B6680 | 100.0% | Reimplemented -SHC_3BB0A8C1_0x004B66C0 | 0.0% | Pending +SHC_3BB0A8C1_0x004B66C0 | 98.3% | The siege engines' colour index and two loads differ SHC_3BB0A8C1_0x004B6C20 | 0.0% | Pending