From 3ec827d5c1f0f04eddc56b64b8678f1e308d0966 Mon Sep 17 00:00:00 2001 From: Alexander Batalov Date: Mon, 7 Nov 2022 10:59:16 +0300 Subject: [PATCH] Fix worldmap position calculation Closes #192 --- src/worldmap.cc | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/worldmap.cc b/src/worldmap.cc index 2821c4f..3d81704 100644 --- a/src/worldmap.cc +++ b/src/worldmap.cc @@ -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; }