summaryrefslogtreecommitdiff
path: root/src/KingSystem/Ecosystem/ecoSystem.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-11-24 02:36:05 +0100
committerLéo Lam <leo@leolam.fr>2021-11-24 02:36:05 +0100
commit6b88a1cebeed1de7923be6fc030de1564e4c2155 (patch)
tree9919cd0905a732833b23ab7a7e23dbf716c08fbe /src/KingSystem/Ecosystem/ecoSystem.cpp
parent0f3cb6e1ecb63e1f514d227ace38944a2685edac (diff)
ksys/eco: Clarify how beco offset calculation works
Diffstat (limited to 'src/KingSystem/Ecosystem/ecoSystem.cpp')
-rw-r--r--src/KingSystem/Ecosystem/ecoSystem.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/KingSystem/Ecosystem/ecoSystem.cpp b/src/KingSystem/Ecosystem/ecoSystem.cpp
index 7a5f2156..ec55222f 100644
--- a/src/KingSystem/Ecosystem/ecoSystem.cpp
+++ b/src/KingSystem/Ecosystem/ecoSystem.cpp
@@ -110,11 +110,15 @@ s32 Ecosystem::getMapArea(const EcoMapInfo& info, f32 posX, f32 posZ) const {
if (info.mHeader->divisor == 10)
x /= 10;
- if (info.mRowOffsets[row] >= info.mRowOffsets[row + 1])
+ const int offset_begin = info.mRowOffsets[row];
+ const int offset_end = info.mRowOffsets[row + 1];
+ if (offset_begin >= offset_end)
return -1;
- auto* segmentEnd = reinterpret_cast<const Segment*>(info.mRows + 2 * info.mRowOffsets[row + 1]);
- auto* segment = reinterpret_cast<const Segment*>(info.mRows + 2 * info.mRowOffsets[row]);
+ // Offsets to segments are divided by 2 and relative to the start of the row section.
+ static constexpr int OffsetMultiplier = 2;
+ auto* segmentEnd = reinterpret_cast<const Segment*>(info.mRows + OffsetMultiplier * offset_end);
+ auto* segment = reinterpret_cast<const Segment*>(info.mRows + OffsetMultiplier * offset_begin);
s32 totalLength = 0;
while (true) {
totalLength += segment->length;