Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
29c08cc
build: compile the WildlifeState and LandscapeState functions of #526…
gynt Dec 4, 2026
cc890ad
reimplement: SHC_3BB0A8C1_0x004F2140 100.00% Reimplemented
gynt Dec 4, 2026
66f36d4
reimplement: SHC_3BB0A8C1_0x004F3960 100.00% Reimplemented
gynt Dec 4, 2026
5c6c924
reimplement: SHC_3BB0A8C1_0x0052D9D0 100.00% Reimplemented
gynt Dec 4, 2026
188e40c
reimplement: SHC_3BB0A8C1_0x0052C570 100.00% Reimplemented
gynt Dec 4, 2026
c9b8196
reimplement: SHC_3BB0A8C1_0x0052C810 100.00% Reimplemented
gynt Dec 4, 2026
6606d30
reimplement: SHC_3BB0A8C1_0x0052D720 100.00% Reimplemented
gynt Dec 4, 2026
2dde257
reimplement: SHC_3BB0A8C1_0x0052D620 100.00% Reimplemented
gynt Dec 4, 2026
0f802a5
reimplement: SHC_3BB0A8C1_0x0052D690 100.00% Reimplemented
gynt Dec 4, 2026
bc2c9b0
reimplement: SHC_3BB0A8C1_0x0052BF40 100.00% Reimplemented
gynt Dec 4, 2026
c2e02a9
reimplement: SHC_3BB0A8C1_0x0052E020 100.00% Reimplemented
gynt Dec 4, 2026
4c78ece
reimplement: SHC_3BB0A8C1_0x0052DF30 100.00% Reimplemented
gynt Dec 4, 2026
b3774fb
style: apply the style guide to the eleven WildlifeState and Landscap…
gynt Dec 4, 2026
cca7f2f
Merge remote-tracking branch 'origin/main' into reimpl/pr526-matched
gynt Dec 4, 2026
71dd139
review: pre-review pass for TheRedDaemon
gynt Dec 4, 2026
83cb7e6
Rename TreeState to TreeStateEnum, TS_ to TSE_
gynt Dec 4, 2026
a953260
Merge origin/main into reimpl/pr526-matched
gynt Dec 4, 2026
c4f4049
Merge origin/main into reimpl/pr526-matched
gynt Dec 4, 2026
c1a47e4
Merge origin/main into reimpl/pr526-matched
gynt Dec 4, 2026
68ea361
review: drop redundant casts
gynt Dec 4, 2026
e998f1f
Merge origin/main into reimpl/pr526-matched
gynt Dec 5, 2026
4524b11
Tree::stageRelated2: undefined2 -> short
gynt Dec 5, 2026
0633805
LandscapeState::createRock: type the parameters
gynt Dec 5, 2026
803c7b2
Add the DebugDataMapDataDisplayType enum
gynt Dec 5, 2026
bb64bd5
updateTreeStage: name the stage slot, set the flag with TRUE
gynt Dec 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ src/OpenSHC/Map/Units/UpdateMinerIronFetcher.cpp
src/OpenSHC/Map/Units/UpdateWorker_ConsiderTakingABreakUnk.cpp
src/OpenSHC/Map/Units/UnitsState/isWorkplaceBuildingOnAdjacentTile.cpp
src/OpenSHC/Map/Units/ConsiderHavingABreakNowUnk.cpp
src/OpenSHC/Map/WildlifeState/floodFillField13FromCell.cpp
src/OpenSHC/Map/WildlifeState/floodFillField20FromCell.cpp
src/OpenSHC/Map/WildlifeState/updateWildlife.cpp
src/OpenSHC/Map/LandscapeState/getValueFrom0UpTo3ForTreeTypeAndTreeStage.cpp
src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp
src/OpenSHC/Map/Units/UnitsState/acquireShootTarget.cpp
src/OpenSHC/Map/Units/UnitsState/calculateUnitMovementSpeed.cpp
src/OpenSHC/Map/Units/UnitsState/chooseHusbandAndWife.cpp
Expand Down
32 changes: 32 additions & 0 deletions src/OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
THIS FILE IS AUTO GENERATED
Communicate changes to the dev team (e.g. via a Pull Request).
Changes get lost otherwise.

path: 'OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp'
*/

#pragma once

namespace OpenSHC {
namespace Map {
namespace Enums {
typedef enum DebugDataMapDataDisplayType {

DDMDDT_CONNECT = 0, // 0x00000000
DDMDDT_CHIMPS = 1, // 0x00000001
DDMDDT_FARMLAND = 2, // 0x00000002
DDMDDT_HUMANS = 3, // 0x00000003
DDMDDT_MANKIND = 4, // 0x00000004
DDMDDT_DEER = 5, // 0x00000005
DDMDDT_ROUTE = 6, // 0x00000006
DDMDDT_PANIC = 7, // 0x00000007
DDMDDT_SIEGE = 8, // 0x00000008
DDMDDT_SLINK = 9 // 0x00000009

} DebugDataMapDataDisplayType;

static_assert_cpp98_obj(sizeof(DebugDataMapDataDisplayType) == 4, DebugDataMapDataDisplayType);
} // namespace Enums
} // namespace Map
} // namespace OpenSHC
21 changes: 21 additions & 0 deletions src/OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
THIS FILE IS AUTO GENERATED
Communicate changes to the dev team (e.g. via a Pull Request).
Changes get lost otherwise.

path: 'OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp'
*/

#pragma once

#include "OpenSHC/Map/Enums/DebugDataMapDataDisplayType.hpp"

namespace OpenSHC {
namespace Map {
namespace Enums {
typedef int DebugDataMapDataDisplayTypeInt;

static_assert_cpp98_obj(sizeof(DebugDataMapDataDisplayTypeInt) == 4, DebugDataMapDataDisplayTypeInt);
} // namespace Enums
} // namespace Map
} // namespace OpenSHC
4 changes: 3 additions & 1 deletion src/OpenSHC/Map/LandscapeState.func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "OpenSHC/Commands/MappersEnum.hpp"
#include "OpenSHC/IO/PackagedFileMagicNum.hpp"
#include "OpenSHC/Map/LandscapeState.hpp"
#include "OpenSHC/Map/Rocks/Enums/RockType.hpp"
#include "OpenSHC/Map/Trees/TreeType.hpp"
#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp"
namespace OpenSHC {
Expand All @@ -13,6 +14,7 @@ namespace Map {

using OpenSHC::Commands::MappersEnum;
using OpenSHC::IO::PackagedFileMagicNum;
using OpenSHC::Map::Rocks::Enums::RockType;
using OpenSHC::Map::Trees::TreeType;
using OpenSHC::WindowsHelper::Enums::BOOLEnum;

Expand Down Expand Up @@ -51,7 +53,7 @@ namespace Map {
&LandscapeState::setCurrentTimeOnSomeTrees)
setCurrentTimeOnSomeTrees;

MACRO_FUNCTION_RESOLVER(int (LandscapeState::*)(undefined4, undefined4, int, undefined4, undefined4), false,
MACRO_FUNCTION_RESOLVER(int (LandscapeState::*)(int, int, RockType, int, int), false,
Address::SHC_3BB0A8C1_0x004F2140, &LandscapeState::createRock)
createRock;

Expand Down
6 changes: 4 additions & 2 deletions src/OpenSHC/Map/LandscapeState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "OpenSHC/Commands/MappersEnum.hpp"
#include "OpenSHC/IO/PackagedFileMagicNum.hpp"
#include "OpenSHC/Map/Rocks/Enums/RockType.hpp"
#include "OpenSHC/Map/Rocks/Rock.hpp"
#include "OpenSHC/Map/Trees/Tree.hpp"
#include "OpenSHC/Map/Trees/TreeType.hpp"
Expand All @@ -24,6 +25,7 @@ namespace Map {
using OpenSHC::Commands::MappersEnum;
using OpenSHC::IO::PackagedFileMagicNum;
using OpenSHC::Map::WindState;
using OpenSHC::Map::Rocks::Enums::RockType;
using OpenSHC::Map::Rocks::Rock;
using OpenSHC::Map::Trees::Tree;
using OpenSHC::Map::Trees::TreeType;
Expand Down Expand Up @@ -73,7 +75,7 @@ namespace Map {

void setCurrentTimeOnSomeTrees();

int createRock(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation);
int createRock(int x, int y, RockType rockType, int size, int orientation);

void removeRock(int rockID);

Expand Down Expand Up @@ -109,7 +111,7 @@ namespace Map {

void updateWind();

void updateTreeStage(uint treeID, uint rng);
void updateTreeStage(uint treeID, uint stageSlot);

int findTree(int playerID, uint unitXPosition, uint unitYPosition);

Expand Down
40 changes: 40 additions & 0 deletions src/OpenSHC/Map/LandscapeState/createRock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include "../LandscapeState.func.hpp"

#include "OpenSHC/Globals/DAT_CurrentRockID.hpp"
#include "OpenSHC/Globals/DAT_GameCore.hpp"
#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp"
#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp"

namespace OpenSHC {
namespace Map {

// FUNCTION: STRONGHOLDCRUSADER 0x004F2140
int LandscapeState::createRock(int x, int y, RockType rockType, int size, int orientation)
{
int rockID;
for (rockID = 1; rockID < countof(this->rocks); rockID++) {
if (this->rocks[rockID].one == 0) {
break;
}
if (rockID >= countof(this->rocks) - 1) {
return 0;
}
}
this->rocks[rockID].uid = DAT_GameCore::instance.uniqueGameObjectTracker;
DAT_GameCore::instance.uniqueGameObjectTracker++;
this->rocks[rockID].size = size;
this->rocks[rockID].y = y;
this->rocks[rockID].one = 1;
this->rocks[rockID].type = rockType;
this->rocks[rockID].x = x;
this->rocks[rockID].tile = this->rocks[rockID].x
+ DAT_ViewportRenderState::instance.translationMatrix[this->rocks[rockID].y].addXgetTile;
this->rocks[rockID].orientation = orientation;
this->rocks[rockID].unknownGMID = DAT_OrganismDefinedData::instance.Rock_field0xe[rockType];
DAT_CurrentRockID::instance = rockID;
DAT_OrganismDefinedData::instance.RockTypeFunctions[this->rocks[rockID].type]();
return rockID;
}

} // namespace Map
} // namespace OpenSHC
106 changes: 106 additions & 0 deletions src/OpenSHC/Map/LandscapeState/updateTreeStage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "../LandscapeState.func.hpp"

#include "OpenSHC/Map/Navigation/PathFindingState.func.hpp"
#include "OpenSHC/Map/TileMapState.func.hpp"
#include "OpenSHC/UI/DisplayElements.func.hpp"
#include "OpenSHC/Game/GameMode.hpp"
#include "OpenSHC/Map/LogicHelpers/Logic1.hpp"
#include "OpenSHC/Map/Trees/TreeStateEnum.hpp"
#include "OpenSHC/Map/Trees/TreeType.hpp"
#include "OpenSHC/Map/Trees/TreeTypeShort.hpp"
#include "OpenSHC/UI/Enums/DisplayElementID.hpp"
#include "OpenSHC/UI/Enums/MenuViewType.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_OrganismDefinedData.hpp"
#include "OpenSHC/Globals/DAT_PathFindingState.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"

namespace OpenSHC {
namespace Map {

// FUNCTION: STRONGHOLDCRUSADER 0x004F3960
void LandscapeState::updateTreeStage(uint treeID, uint stageSlot)
{
if (DAT_GameSynchronyState::instance.currentGameMode == Game::GM_SOLITARY) {
if (DAT_GameCore::instance.isTimeHalted) {
return;
}
if (MACRO_CALL(UI::DisplayElements_Func::GetIfDisplayElementStateNotZero)(
UI::Enums::DEID_KEEP_AND_GRANERY_PLACEMENT_INFO)) {
return;
}
}
// updateTrees draws one random slot (0 to 63) every eighth tick; a tree only advances in its own slot
if ((this->trees[treeID].rng1 & 0x3fU) != stageSlot) {
return;
}
int const treeType = this->trees[treeID].treeType;
// the shrubs and the apple tree do not advance their stage here
if (treeType >= Trees::TT_SHRUB_NEEDLE_PALM_A && treeType <= Trees::TT_SHRUB_PRICKLYPEAR) {
return;
}
if (this->trees[treeID].zeroUpTo2 != 0) {
return;
}
if (this->trees[treeID].stageRelated1 < this->trees[treeID].stageRelated2) {
return;
}
if (!this->field_0x4) {
return;
}
if (DAT_GameCore::instance.currentMenuViewType == UI::Enums::MVT_MAP_EDITOR_LANDSCAPING) {
return;
}
this->trees[treeID].stageTracker++;
if (this->trees[treeID].stageTracker
< DAT_OrganismDefinedData::instance.TreeStageLevels[treeType][this->trees[treeID].stage + 1]) {
return;
}
this->trees[treeID].stage++;
MACRO_CALL_MEMBER(Map::LandscapeState_Func::setTreeStageRelatedValues, this)(treeID, this->trees[treeID].stage);
if (this->trees[treeID].stage >= 6) {
this->trees[treeID].state = Trees::TSE_TO_BE_REMOVED;
return;
}
if (this->trees[treeID].stage < 4) {
return;
}
DAT_GameState::instance.mapAndTime.treeSpreadCounter++;
if (DAT_GameState::instance.mapAndTime.treeSpreadCounter
> DAT_GameState::instance.mapAndTime.treeSpreadInterval) {
DAT_GameState::instance.mapAndTime.treeSpreadCounter = 0;
this->trees[treeID].stage = 5;
this->trees[treeID].stageTracker
= DAT_OrganismDefinedData::instance.TreeStageLevels[this->trees[treeID].treeType][5];
return;
}
// set the spread counter to the lowest value for the tree type
this->trees[treeID].stageTracker
= DAT_OrganismDefinedData::instance.TreeStageLevels[this->trees[treeID].treeType][3];
this->trees[treeID].stage = 3;
DAT_GameState::instance.mapAndTime.newOrganismsValue2++;
if (!MACRO_CALL_MEMBER(Map::LandscapeState_Func::setupBabyTreeLocation, this)(
treeID, this->trees[treeID].treeType, this->trees[treeID].xPosition, this->trees[treeID].yPosition)) {
return;
}
int const size = MACRO_CALL_MEMBER(Map::LandscapeState_Func::getValueFrom0UpTo3ForTreeTypeAndTreeStage,
DAT_LandscapeState::ptr)(this->trees[treeID].treeType, 0);
int const newTreeID = MACRO_CALL_MEMBER(Map::LandscapeState_Func::createTree, DAT_LandscapeState::ptr)(
DAT_PathFindingState::instance.ALG_ResultX, DAT_PathFindingState::instance.ALG_ResultY,
(TreeType)this->trees[treeID].treeType, size, 0, 0, 0);
DAT_TileMapState::instance.LogicLayer[DAT_PathFindingState::instance.ALG_ResultTile] |= LogicHelpers::L_TREE;
DAT_TileMapState::instance.OrganismLayer[DAT_PathFindingState::instance.ALG_ResultTile] = newTreeID;
MACRO_CALL_MEMBER(Map::TileMapState_Func::applyTreeBrushToLogicalLayer, DAT_TileMapState::ptr)(newTreeID, 0);
MACRO_CALL_MEMBER(Map::Navigation::PathFindingState_Func::updatePathLinkagesInAllEightDirections,
DAT_PathFindingState::ptr)(this->trees[newTreeID].yPosition, this->trees[newTreeID].tile);
DAT_GameState::instance.mapAndTime.newOrganisms++;
DAT_PathFindingState::instance.toggleUpdateSeparateAreaTileMap = TRUE;
}

} // namespace Map
} // namespace OpenSHC
2 changes: 1 addition & 1 deletion src/OpenSHC/Map/Trees/Tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace Map {
short param_6; // 0x0000006E length: 2
undefined1 padding_0x70[2]; // 0x00000070 length: 2
short stageRelated1; // 0x00000072 length: 2
undefined2 stageRelated2; // 0x00000074 length: 2
short stageRelated2; // 0x00000074 length: 2
short zeroUpTo2; // 0x00000076 length: 2
short treeAdultHoodStageRelatedVisual3; // 0x00000078 length: 2
undefined2 stageRelated4; // 0x0000007A length: 2
Expand Down
4 changes: 3 additions & 1 deletion src/OpenSHC/Map/WildlifeState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

#pragma once

#include "OpenSHC/Map/Enums/DebugDataMapDataDisplayTypeInt.hpp"
#include "OpenSHC/Map/Wildlife/WildlifeGridElement.hpp"
#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp"

namespace OpenSHC {
namespace Map {

using OpenSHC::Map::Enums::DebugDataMapDataDisplayTypeInt;
using OpenSHC::Map::Wildlife::WildlifeGridElement;
using OpenSHC::WindowsHelper::Enums::BOOLEnum;

Expand All @@ -23,7 +25,7 @@ namespace Map {
class WildlifeState {
public:
WildlifeGridElement grid[40][40]; // 0x00000000 length: 256000
int DAT_DebugDataMapDataDisplayType; // 0x0003E800 length: 4
DebugDataMapDataDisplayTypeInt DAT_DebugDataMapDataDisplayType; // 0x0003E800 length: 4
int casDisRelated; // 0x0003E804 length: 4
int candidateIndex; // 0x0003E808 length: 4
int candidateIndex2; // 0x0003E80C length: 4
Expand Down
76 changes: 76 additions & 0 deletions src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "../WildlifeState.func.hpp"

#include "OpenSHC/Map/MapConstants.hpp"

#include "OpenSHC/Globals/DAT_GameState.hpp"
#include "OpenSHC/Globals/DAT_TerrainDefinedData.hpp"
#include "OpenSHC/Globals/DAT_TroopValueState.hpp"

namespace OpenSHC {
namespace Map {

// FUNCTION: STRONGHOLDCRUSADER 0x0052D9D0
void WildlifeState::floodFillCasDisFromSignpost()
{
int const x = DAT_GameState::instance.mapAndTime
.signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4]
.x
/ MC_MAP_SECTOR_SIZE;
int const y = DAT_GameState::instance.mapAndTime
.signpostEntryData[DAT_TroopValueState::instance.attackInfo.field_0x469d4]
.y
/ MC_MAP_SECTOR_SIZE;
this->casDisRelated = 1;
this->candidateIndex = 0;
this->candidateIndex2 = 1;
for (int row = 0; row < countof(this->grid[0]); row++) {
for (int column = 0; column < countof(this->grid); column++) {
this->grid[column][row].casDisRelated2 = 0;
this->grid[column][row].field_0x74 = 0;
}
}
this->DAT_Y10_Array_Section1034[0] = (short)y;
this->DAT_X10_Array_Section1034[0] = (short)x;
int const areaID = this->grid[x][y].separateAreaID;
this->grid[x][y].casDisRelated2 = 1;
for (; this->candidateIndex != this->candidateIndex2;) {
int const candidateX = this->DAT_X10_Array_Section1034[this->candidateIndex];
int const candidateY = this->DAT_Y10_Array_Section1034[this->candidateIndex];
this->casDisRelated = this->grid[candidateX][candidateY].casDisRelated2;
if (this->casDisRelated >= 100) {
break;
}
int const level = this->casDisRelated + 1;
for (int direction = 0;
direction < countof(DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix); direction++) {
uint const neighbourX
= DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.xOffset
+ candidateX;
uint const neighbourY
= DAT_TerrainDefinedData::instance.clockwiseCardinalTranslationMatrix[direction].int_.yOffset
+ candidateY;
if (neighbourX > countof(this->grid) - 1 || neighbourY > countof(this->grid[0]) - 1
|| this->grid[neighbourX][neighbourY].firstMember <= 0
|| areaID != this->grid[neighbourX][neighbourY].separateAreaID
|| this->grid[neighbourX][neighbourY].unknownNonZero01 != 0
|| this->grid[neighbourX][neighbourY].casDisRelated2 != 0) {
continue;
}
this->grid[neighbourX][neighbourY].casDisRelated2 = level;
this->grid[neighbourX][neighbourY].field_0x74++;
this->DAT_X10_Array_Section1034[this->candidateIndex2] = neighbourX;
this->DAT_Y10_Array_Section1034[this->candidateIndex2] = neighbourY;
this->candidateIndex2++;
if (this->candidateIndex2 >= countof(this->DAT_X10_Array_Section1034)) {
this->candidateIndex2 = 0;
}
}
this->candidateIndex++;
if (this->candidateIndex >= countof(this->DAT_X10_Array_Section1034)) {
this->candidateIndex = 0;
}
}
}

} // namespace Map
} // namespace OpenSHC
Loading
Loading