Skip to content

Reimplement adjacent tile region and height check - #227

Open
Krarilotus wants to merge 1 commit into
sourcehold:mainfrom
Krarilotus:reimplement/moat-adjacent-access
Open

Reimplement adjacent tile region and height check#227
Krarilotus wants to merge 1 commit into
sourcehold:mainfrom
Krarilotus:reimplement/moat-adjacent-access

Conversation

@Krarilotus

Copy link
Copy Markdown
Contributor

TL;DR: Reimplements the game's check for a neighboring tile in a requested path region, as used during moat selection. The C++ makes the height rule explicit while preserving the original behavior.

Implements TileMapState::findTileInSameAreaAndNoTooHeightDifference at 0x00500370. It examines eight offsets from the caller's row, accepts a neighbor no more than 16 height units above the source tile, and compares its signed 16-bit region ID with the requested area. This is an existence check: route selection, terrain suitability, and caller input validation remain outside this helper.

Validation: built the linked OpenSHC.dll with MSVC 2005 SP1 in RelWithDebInfo and compared it against Crusader 1.41 with reccmp. Result: 100% effective match. The sole difference is the ordering of two independent setup instructions (add edx, ecx and lea ebx, [eax + 0x10]); the loop, comparisons, and returns match. This is not claimed as a byte-for-byte match or a gameplay fix.

No generated headers, runtime infrastructure, or emulator tooling are changed.

@TheRedDaemon TheRedDaemon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing the matching status file update.

Comment on lines +9 to +12
int direction = 0;
int* neighborOffset = this->directionTranslationMatrix[row];
for (; direction < 8; ++direction, ++neighborOffset) {
int neighborTile = tile + *neighborOffset;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if this loop would also work by index access and iterating over the directions?
Basically a normal for-loop and then using this->directionTranslationMatrix[row][direction]?
If not might neighborOffset[direction] possible, avoiding the pointer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants