Fix worldmap position calculation

Closes #192
This commit is contained in:
Alexander Batalov 2022-11-07 10:59:16 +03:00
parent c692fc91af
commit 3ec827d5c1
1 changed files with 22 additions and 5 deletions

View File

@ -849,6 +849,15 @@ int wmWorldMap_init()
gTownMapHotkeysFix = true;
configGetBool(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_TOWN_MAP_HOTKEYS_FIX_KEY, &gTownMapHotkeysFix);
// CE: City size fids should be initialized during startup. They are used
// during |wmTeleportToArea| to calculate worldmap position when jumping
// from Temple to Arroyo - before giving a chance to |wmInterfaceInit| to
// initialize it.
for (int citySize = 0; citySize < CITY_SIZE_COUNT; citySize++) {
CitySizeDescription* citySizeDescription = &(wmSphereData[citySize]);
citySizeDescription->fid = buildFid(OBJ_TYPE_INTERFACE, 336 + citySize, 0, 0, 0);
}
return 0;
}
@ -4469,11 +4478,7 @@ static int wmInterfaceInit()
for (int citySize = 0; citySize < CITY_SIZE_COUNT; citySize++) {
CitySizeDescription* citySizeDescription = &(wmSphereData[citySize]);
fid = buildFid(OBJ_TYPE_INTERFACE, 336 + citySize, 0, 0, 0);
citySizeDescription->fid = fid;
if (!citySizeDescription->frmImage.lock(fid)) {
if (!citySizeDescription->frmImage.lock(citySizeDescription->fid)) {
return -1;
}
}
@ -6540,9 +6545,21 @@ int wmTeleportToArea(int areaIdx)
// locations.
// CE: See `wmWorldMapFunc` for explanation.
CitySizeDescription* citySizeDescription = &(wmSphereData[city->size]);
// CE: This function might be called outside |wmWorldmapFunc|, so it's
// image might not be locked.
bool wasLocked = citySizeDescription->frmImage.isLocked();
if (!wasLocked) {
citySizeDescription->frmImage.lock(citySizeDescription->fid);
}
wmGenData.worldPosX = city->x + citySizeDescription->frmImage.getWidth() / 2 - WM_VIEW_X;
wmGenData.worldPosY = city->y + citySizeDescription->frmImage.getHeight() / 2 - WM_VIEW_Y;
if (!wasLocked) {
citySizeDescription->frmImage.unlock();
}
return 0;
}