Skip to content

Commit 3ec827d

Browse files
committed
Fix worldmap position calculation
Closes #192
1 parent c692fc9 commit 3ec827d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/worldmap.cc

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,15 @@ int wmWorldMap_init()
849849
gTownMapHotkeysFix = true;
850850
configGetBool(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_TOWN_MAP_HOTKEYS_FIX_KEY, &gTownMapHotkeysFix);
851851

852+
// CE: City size fids should be initialized during startup. They are used
853+
// during |wmTeleportToArea| to calculate worldmap position when jumping
854+
// from Temple to Arroyo - before giving a chance to |wmInterfaceInit| to
855+
// initialize it.
856+
for (int citySize = 0; citySize < CITY_SIZE_COUNT; citySize++) {
857+
CitySizeDescription* citySizeDescription = &(wmSphereData[citySize]);
858+
citySizeDescription->fid = buildFid(OBJ_TYPE_INTERFACE, 336 + citySize, 0, 0, 0);
859+
}
860+
852861
return 0;
853862
}
854863

@@ -4469,11 +4478,7 @@ static int wmInterfaceInit()
44694478

44704479
for (int citySize = 0; citySize < CITY_SIZE_COUNT; citySize++) {
44714480
CitySizeDescription* citySizeDescription = &(wmSphereData[citySize]);
4472-
4473-
fid = buildFid(OBJ_TYPE_INTERFACE, 336 + citySize, 0, 0, 0);
4474-
citySizeDescription->fid = fid;
4475-
4476-
if (!citySizeDescription->frmImage.lock(fid)) {
4481+
if (!citySizeDescription->frmImage.lock(citySizeDescription->fid)) {
44774482
return -1;
44784483
}
44794484
}
@@ -6540,9 +6545,21 @@ int wmTeleportToArea(int areaIdx)
65406545
// locations.
65416546
// CE: See `wmWorldMapFunc` for explanation.
65426547
CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]);
6548+
6549+
// CE: This function might be called outside |wmWorldmapFunc|, so it's
6550+
// image might not be locked.
6551+
bool wasLocked = citySizeDescription->frmImage.isLocked();
6552+
if (!wasLocked) {
6553+
citySizeDescription->frmImage.lock(citySizeDescription->fid);
6554+
}
6555+
65436556
wmGenData.worldPosX = city->x + citySizeDescription->frmImage.getWidth() / 2 - WM_VIEW_X;
65446557
wmGenData.worldPosY = city->y + citySizeDescription->frmImage.getHeight() / 2 - WM_VIEW_Y;
65456558

6559+
if (!wasLocked) {
6560+
citySizeDescription->frmImage.unlock();
6561+
}
6562+
65466563
return 0;
65476564
}
65486565

0 commit comments

Comments
 (0)