diff --git a/docs/changelog.txt b/docs/changelog.txt index e078c870da..d5e9d33ec2 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -73,6 +73,7 @@ Template for new versions: - `buildingplan`: fix "Unlink all" only unlinking some mechanisms (or crashing) when freeing mechanisms from the building - `timestream`: deal properly with units who have breathing difficulties - `stocks`: overlay now resets scroll position when collapsing categories so the item list is no longer left blank and unscrollable +- Fixed persistent site data API (``dfhack.persistent.saveSiteData``/``getSiteData``) failing on newly reclaimed fortresses until the first save ## Misc Improvements - Added ``Coord2d`` and ``Coord3d`` C++ templates, providing a standard set operations for 2-tuples and 3-tuples of any numeric type diff --git a/library/modules/World.cpp b/library/modules/World.cpp index c0c6d590fd..020e76127d 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -217,8 +217,15 @@ df::unit * World::getAdventurer() { int32_t World::GetCurrentSiteId() { if (!plotinfo) return -1; - if (isFortressMode()) - return plotinfo->site_id; + if (isFortressMode()) { + // on a reclaimed fortress, site_id isn't assigned until the first + // save; fortress_site is set at embark, so use it as a fallback + if (plotinfo->site_id >= 0) + return plotinfo->site_id; + if (auto site = plotinfo->main.fortress_site) + return site->id; + return -1; + } if (auto adv = getAdventurer(); adv && world->world_data) { DEBUG(world).print("searching for adventure site\n"); auto & world_map = world->map;