Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0cb22d2
Copy 11 functions from gynt's catch-all branches to reimpl/landscape-…
gynt Nov 28, 2026
61c578e
Fix compile errors against main's headers
gynt Nov 28, 2026
02c7662
reimplement: status of 11 ported functions
gynt Nov 28, 2026
e8d11cb
Wildlife: updateNofFpoints and updateWildlife as plain grid loops
gynt Nov 28, 2026
fbf0561
LandscapeState: updateTreeStage and createRock follow the binary
gynt Nov 28, 2026
e32e5d8
LandscapeState: spawnCrowFromNearbyTree as plain loops
gynt Nov 28, 2026
828ff62
Wildlife: rebuild renderDebugDataMapData, end the row loop
gynt Nov 28, 2026
91892c4
Wildlife: buildRallyPointPathForTribe as plain direction loops
gynt Nov 28, 2026
23e7c40
Wildlife: rebuild findAndSetNewRallyPointForDeerAndLions
gynt Nov 28, 2026
6f3fde9
LandscapeState: createTree slot search and switch follow the binary
gynt Nov 28, 2026
36912ae
Wildlife: updateWildlifeGrid as plain loops over named arrays
gynt Nov 28, 2026
e3274b4
LandscapeState: createRock store order reaches 100%
gynt Nov 28, 2026
4d1bc21
types: AttackInfo::nof_fpointsArray holds 100 entries
gynt Nov 28, 2026
b52870b
Wildlife: updateNofFpoints clears all 100 fpoint entries
gynt Nov 28, 2026
4d2ab6f
LandscapeState: createTree stores yPosition after treeType
gynt Nov 28, 2026
4623340
Wildlife: updateSection1034Info walks the grid, not past it
gynt Nov 28, 2026
49f1235
Wildlife: reimplement hasAdjacentCellWithField24Or25
gynt Nov 28, 2026
c1303a1
Wildlife: reimplement isAttackStagingCandidateCell
gynt Nov 28, 2026
ccef45b
Wildlife: reimplement floodFillZoneProximityFromCell
gynt Nov 28, 2026
1a970fa
Wildlife: reimplement floodFillCasDisFromSignpost
gynt Nov 28, 2026
8b1e129
Wildlife: build updateSection1034Info, updateNofFpoints and callees w…
gynt Nov 28, 2026
fd84535
status: updateSection1034Info 94.0, updateNofFpoints 67.0 under /GL
gynt Nov 28, 2026
13b3ae6
Wildlife: updateNofFpoints scans with a y induction variable
gynt Nov 28, 2026
c5d880c
Wildlife: reimplement floodFillField13FromCell
gynt Nov 28, 2026
f21ddca
Wildlife: reimplement floodFillField20FromCell
gynt Nov 28, 2026
39e3627
Wildlife: build updateWildlife and its two flood fills with /GL
gynt Nov 28, 2026
10ec508
status: updateWildlife 100% under /GL
gynt Nov 28, 2026
a9712dd
LandscapeState: build updateTreeStage and its tree-size callee with /GL
gynt Nov 28, 2026
9e14d1e
status: updateTreeStage 100% under /GL
gynt Nov 28, 2026
94652a0
Wildlife: updateWildlifeGrid unit arms in the original's layout
gynt Nov 29, 2026
b4fbd64
Wildlife: rally point search tests the lion count last in both arms
gynt Nov 29, 2026
d2a5f60
Wildlife: renderDebugDataMapData draws the box in every colour arm
gynt Nov 29, 2026
c8fde8b
Wildlife: buildRallyPointPathForTribe reads the tribe's y before its x
gynt Nov 29, 2026
73fe525
Wildlife: findAndSetNewRallyPointForDeerAndLions reads the tribe's y …
gynt Nov 29, 2026
89e489a
Merge origin/main into reimpl/landscape-wildlife-development
gynt Dec 2, 2026
3047d59
Landscape/Wildlife: adapt sources to main's headers
gynt Dec 2, 2026
8f17203
Merge origin/main into reimpl/landscape-wildlife-development
gynt Dec 3, 2026
20b6e50
status: updateNofFpoints measures 77.5% after the merge with main
gynt Dec 3, 2026
9b623d5
reimplement: SHC_3BB0A8C1_0x0052E020 100.00% Reimplemented
gynt Dec 4, 2026
71461c2
reimplement: SHC_3BB0A8C1_0x0052CFE0 94.58% Stack slot layout differs
gynt Dec 4, 2026
f35c83b
reimplement: SHC_3BB0A8C1_0x0052CAB0 88.62% Stack slot layout differs
gynt Dec 4, 2026
10217ac
reimplement: SHC_3BB0A8C1_0x0052BA10 87.47% ebx/ebp swap tile vs zero
gynt Dec 4, 2026
1171023
reimplement: SHC_3BB0A8C1_0x0052CFE0 97.95% param_2 copy scheduling
gynt Dec 4, 2026
ca81410
reimplement: SHC_3BB0A8C1_0x0052CAB0 96.11% x/cell slot swap
gynt Dec 4, 2026
8290405
Merge remote-tracking branch 'origin/main' into d526
gynt Dec 5, 2026
e7cffbf
updateNofFpoints: signed bounds check on x and y (86.6%)
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
11 changes: 11 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,17 @@ 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/hasAdjacentCellWithField24Or25.cpp
src/OpenSHC/Map/WildlifeState/isAttackStagingCandidateCell.cpp
src/OpenSHC/Map/WildlifeState/floodFillZoneProximityFromCell.cpp
src/OpenSHC/Map/WildlifeState/floodFillCasDisFromSignpost.cpp
src/OpenSHC/Map/WildlifeState/updateSection1034Info.cpp
src/OpenSHC/Map/WildlifeState/updateNofFpoints.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
42 changes: 42 additions & 0 deletions src/OpenSHC/Map/LandscapeState/createRock.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "../../Map.func.hpp"
#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(undefined4 x, undefined4 y, int rockType, undefined4 size, undefined4 orientation)
{
// find a free rock slot
int _rockID;
for (_rockID = 1; _rockID < 4000; _rockID++) {
if (this->rocks[_rockID].one == 0) {
break;
}
if (_rockID >= 3999) {
return 0;
}
}
this->rocks[_rockID].uid = DAT_GameCore::instance.uniqueGameObjectTracker;
DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1;
this->rocks[_rockID].size = (short)size;
this->rocks[_rockID].y = (ushort)y;
this->rocks[_rockID].one = 1;
this->rocks[_rockID].type = (short)rockType;
this->rocks[_rockID].x = (ushort)x;
this->rocks[_rockID].tile
= (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile;
this->rocks[_rockID].orientation = (short)orientation;
this->rocks[_rockID].unknownGMID = (short)DAT_OrganismDefinedData::instance.Rock_field0xe[rockType];
DAT_CurrentRockID::instance = _rockID;
(*DAT_OrganismDefinedData::instance.RockTypeFunctions[this->rocks[_rockID].type])();
return _rockID;
}

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

#include "OpenSHC/Map/Trees/TreeTypeShort.hpp"

#include "OpenSHC/Globals/DAT_CurrentTreeID.hpp"
#include "OpenSHC/Globals/DAT_GameCore.hpp"
#include "OpenSHC/Globals/DAT_OrganismDefinedData.hpp"
#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"
#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp"

namespace OpenSHC {
namespace Map {
using Map::Trees::TreeTypeShort;

// FUNCTION: STRONGHOLDCRUSADER 0x004F1CE0
int LandscapeState::createTree(undefined4 x, undefined4 y, TreeType treeType, undefined4 size,
int stageRelatedValue, undefined4 param_6, int stage)
{
undefined2 uVar1;
undefined4 uVar3;
int uVar4;
uint _tile;
/*
*** Find a free tree slot ***
*/
int _treeID;
for (_treeID = 1; _treeID < 2000; _treeID++) {
if (!this->trees[_treeID].state) {
break;
}
if (_treeID >= 1999) {
return 0;
}
}
/*
*** Increment the max tree count on this map ***
*/
if (_treeID >= this->maxTreeCount) {
this->maxTreeCount = _treeID + 1;
}
/*
*** Assign uid to tree ***
*/
this->trees[_treeID].uid = DAT_GameCore::instance.uniqueGameObjectTracker;
DAT_GameCore::instance.uniqueGameObjectTracker = DAT_GameCore::instance.uniqueGameObjectTracker + 1;
/*
*** Set initial state of tree ***
*/
switch (treeType) {
case (TreeType)16:
case (TreeType)17:
case (TreeType)18:
case (TreeType)19:
this->trees[_treeID].state = 4;
break;
default:
this->trees[_treeID].state = 1;
}
/*
*** Set (initial) values for tree ***
*/
this->trees[_treeID].size = (short)size;
this->trees[_treeID].xPosition = (ushort)x;
this->trees[_treeID].treeType = (TreeTypeShort)treeType;
_tile
= (int)(short)(ushort)x + DAT_ViewportRenderState::instance.translationMatrix[(short)(ushort)y].addXgetTile;
this->trees[_treeID].microX = (ushort)x * 8 + 3;
this->trees[_treeID].microY = (ushort)y * 8 + 3;
this->trees[_treeID].tile = _tile;
this->trees[_treeID].rng1 = DAT_TileMapState::instance.RandomLayer[_tile] & 0x7ff;
this->trees[_treeID].appleTreeColorVariation = stageRelatedValue;
this->trees[_treeID].param_6 = (short)param_6;
this->trees[_treeID].yPosition = (ushort)y;
this->trees[_treeID].treeTypeBasedValue1
= (short)DAT_OrganismDefinedData::instance.TreeTypeBasedValueMapping[treeType];
uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated1[treeType][stage];
this->trees[_treeID].stageRelated4 = uVar1;
this->trees[_treeID].treeAdultHoodStageRelatedVisual3 = uVar1;
uVar1 = (undefined2)DAT_OrganismDefinedData::instance.TreeRelated2[treeType][stage];
this->trees[_treeID].stageRelated2 = uVar1;
this->trees[_treeID].stageRelated1 = uVar1;
this->trees[_treeID].gmOriginX = (short)DAT_TextureRenderCoreObject::instance
.gmFileHeaderColorpaletteArray[this->trees[_treeID].treeTypeBasedValue1]
.originX;
this->trees[_treeID].gmOriginY = (short)DAT_TextureRenderCoreObject::instance
.gmFileHeaderColorpaletteArray[this->trees[_treeID].treeTypeBasedValue1]
.originY;
this->trees[_treeID].treeTypeRelated2 = DAT_OrganismDefinedData::instance.field_0x854[treeType];
this->trees[_treeID].zero = 0;
this->trees[_treeID].animationFrameIndex = DAT_TileMapState::instance.RandomLayer[_tile] & 0x1f;
this->trees[_treeID].one = 1;
this->trees[_treeID].stage = stage;
this->trees[_treeID].stageTracker = DAT_OrganismDefinedData::instance.TreeStageLevels[treeType][stage];
DAT_CurrentTreeID::instance = _treeID;
/*
*** Set tree type dependent values ***
*/
switch (treeType) {
case ((TreeType)1):
uVar4 = this->trees[_treeID].rng1 & 0xf;
this->trees[_treeID].appleTreeColorVariation = uVar4;
if (uVar4 >= 15) {
this->trees[_treeID].appleTreeColorVariation = 4;
break;
}
if (uVar4 >= 13) {
this->trees[_treeID].appleTreeColorVariation = 6;
break;
}
if (uVar4 >= 11) {
this->trees[_treeID].appleTreeColorVariation = 1;
break;
}
if (uVar4 <= 8) {
break;
}
goto noColourVariation;
case ((TreeType)2):
uVar4 = this->trees[_treeID].rng1 & 0xf;
this->trees[_treeID].appleTreeColorVariation = uVar4;
if (8 < uVar4) {
this->trees[_treeID].appleTreeColorVariation = 8;
}
break;
case ((TreeType)3):
this->trees[_treeID].appleTreeColorVariation = _treeID % 9;
break;
case ((TreeType)4):
uVar4 = this->trees[_treeID].rng1 & 0xf;
this->trees[_treeID].appleTreeColorVariation = uVar4;
if (uVar4 >= 15) {
this->trees[_treeID].appleTreeColorVariation = 4;
} else if (uVar4 >= 13) {
this->trees[_treeID].appleTreeColorVariation = 6;
} else if (uVar4 >= 11) {
this->trees[_treeID].appleTreeColorVariation = 1;
} else if (uVar4 > 8) {
this->trees[_treeID].appleTreeColorVariation = 0;
}
if (this->trees[_treeID].appleTreeColorVariation <= 8) {
break;
}
goto noColourVariation;
case ((TreeType)6):
this->trees[_treeID].appleTreeColorVariation = 3;
this->trees[_treeID].stage = 4;
break;
case ((TreeType)7):
this->trees[_treeID].appleTreeColorVariation = 4;
this->trees[_treeID].stage = 4;
break;
case ((TreeType)8):
this->trees[_treeID].appleTreeColorVariation = 7;
this->trees[_treeID].stage = 4;
break;
case ((TreeType)9):
this->trees[_treeID].appleTreeColorVariation = 8;
this->trees[_treeID].stage = 4;
break;
case ((TreeType)5):
case ((TreeType)10):
case ((TreeType)0x10):
case ((TreeType)0x11):
case ((TreeType)0x12):
case ((TreeType)0x13):
this->trees[_treeID].stage = 4;
noColourVariation:
this->trees[_treeID].appleTreeColorVariation = 0;
break;
}
uVar3 = this->field_0x0;
this->field_0x0 = 0;
/*
*** Update the tree state ***
*/
(*DAT_OrganismDefinedData::instance.UpdateTree[(short)this->trees[_treeID].treeType])();
this->field_0x0 = uVar3;
return _treeID;
}

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

#include "OpenSHC/Audio/SFX/SFXState.func.hpp"
#include "OpenSHC/Map/Entities/EntityState.func.hpp"
#include "OpenSHC/Random/RNG.func.hpp"
#include "OpenSHC/DE/SHCDE/eSFX.hpp"
#include "OpenSHC/Game/Player/Enums/BuildingEntryInfoEnum.hpp"
#include "OpenSHC/Game/Player/PlayerData.hpp"
#include "OpenSHC/Map/Entities/EntityType.hpp"

#include "OpenSHC/Globals/DAT_EntityState.hpp"
#include "OpenSHC/Globals/DAT_GameState.hpp"
#include "OpenSHC/Globals/DAT_SFXState.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"
#include "OpenSHC/Globals/DAT_UnitsState.hpp"
#include "OpenSHC/Globals/SEC_RNG.hpp"

namespace OpenSHC {
namespace Map {

using DE::SHCDE::eSFX;
using Game::Player::PlayerData;
using Map::Entities::EntityType;

// FUNCTION: STRONGHOLDCRUSADER 0x004F3150
void LandscapeState::spawnCrowFromNearbyTree(int unitID)
{
BOOL playedSound = FALSE;
for (int direction = 0; direction < 8; direction++) {
int const y = DAT_UnitsState::instance.units[unitID].y;
short const treeID = DAT_TileMapState::instance
.OrganismLayer[DAT_TileMapState::instance.directionTranslationMatrix[y][direction]
+ DAT_UnitsState::instance.units[unitID].tile];
if (treeID == 0 || treeID >= this->maxTreeCount) {
continue;
}
if (this->trees[treeID].state != 2 || this->trees[treeID].hasCrow == 0
|| this->trees[treeID].rng200till300 != 0) {
continue;
}
int const playerID = DAT_UnitsState::instance.units[unitID].owner;
int targetX = 0;
int targetY = 0;
int closestDistance = 10000;
for (int keepPlayerID = 1; keepPlayerID < 9; keepPlayerID++) {
if (keepPlayerID == playerID
|| !DAT_GameState::instance.playerDataArray[keepPlayerID]
.buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]
.id) {
continue;
}
int const distanceX = abs(DAT_UnitsState::instance.units[unitID].x
- DAT_GameState::instance.playerDataArray[keepPlayerID]
.buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]
.xEntry);
int const distanceY = abs(y
- DAT_GameState::instance.playerDataArray[keepPlayerID]
.buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]
.yEntry);
int const distance = distanceX > distanceY ? distanceX : distanceY;
if (distance < closestDistance) {
targetX = SEC_RNG::instance.currentNumber2 % 5 - 2
+ DAT_GameState::instance.playerDataArray[keepPlayerID]
.buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]
.xEntry;
targetY = (SEC_RNG::instance.currentNumber2 >> 8) % 5 - 2
+ DAT_GameState::instance.playerDataArray[keepPlayerID]
.buildingEntryInfos[OpenSHC::Game::Player::Enums::BEIE_KEEP]
.yEntry;
closestDistance = distance;
}
}
if (closestDistance == 10000) {
targetX = DAT_UnitsState::instance.units[unitID].x - 50 + SEC_RNG::instance.currentNumber2 % 100;
targetY = (SEC_RNG::instance.currentNumber2 >> 8) % 100 - 50 + y;
MACRO_CALL_MEMBER(Random::RNG_Func::nextRandomNumber2, SEC_RNG::ptr)();
}
MACRO_CALL_MEMBER(Map::Entities::EntityState_Func::spawnProjectileEntity, DAT_EntityState::ptr)(unitID,
DAT_UnitsState::instance.units[unitID].owner, 0, this->trees[treeID].xPosition * 8,
this->trees[treeID].yPosition * 8,
DAT_TileMapState::instance.HeightLayer[this->trees[treeID].tile] + 30, targetX * 8, targetY * 8, 250,
Map::Entities::EntityTypeInt__ET_CROW, 0);
this->trees[treeID].rng200till300 = SEC_RNG::instance.currentNumber2 % 100 + 200;
if (!playedSound) {
MACRO_CALL_MEMBER(Audio::SFX::SFXState_Func::playSFXAtLocation, DAT_SFXState::ptr)(
this->trees[treeID].xPosition, this->trees[treeID].yPosition, DE::SHCDE::FX_CROW);
playedSound = TRUE;
}
}
}

}
}
Loading