fix(compat): restore wind coverage startup and entity hiding

Defer wind coverage changes until prefab data is ready and preserve retryable activation state.

Replace fixed raycast local slots with semantic entity-field matching and guard fallback paths.
This commit is contained in:
soarqin committed 2026-09-24 13:37:30 +08:00
1 parent 8a10fc909a
commit 60d54ac918
5 files changed
+44 -33

No files matched your search

+2
View File
@@ -3,6 +3,8 @@
## Changlog
* Unreleased
* `PowerGlobalCoverage`: Fix a startup crash before wind-turbine prefabs finish loading. Retry after preload without corrupting activation state or the original power ranges, and tolerate unallocated factory data.
* 2.4.5
* Support Dyson Sphere Program 0.10.35.29057.
* Update `Terraform anyway` for the separate foundation and Restore Terrain workflows. Preserve soil gains and prevent negative soil balances when resources are insufficient.
@@ -181,25 +181,27 @@ internal static class WindTurbinesPowerGlobalCoverage
if (enable)
{
if (_patched) return;
var prefabDesc = LDB.items?.Select(WindTurbineId)?.prefabDesc;
if (prefabDesc == null) return;
_oldCoverRadius = prefabDesc.powerCoverRadius;
_oldConnectDistance = prefabDesc.powerConnectDistance;
prefabDesc.powerCoverRadius = WindTurbineNewCoverageDistance;
prefabDesc.powerConnectDistance = WindTurbineNewCoverageDistance;
_prefabdesc = prefabDesc;
_patched = true;
var itemProto = LDB.items.Select(WindTurbineId);
_oldCoverRadius = itemProto.prefabDesc.powerCoverRadius;
_oldConnectDistance = itemProto.prefabDesc.powerConnectDistance;
itemProto.prefabDesc.powerCoverRadius = WindTurbineNewCoverageDistance;
itemProto.prefabDesc.powerConnectDistance = WindTurbineNewCoverageDistance;
_prefabdesc = itemProto.prefabDesc;
}
else
{
if (!_patched) return;
_patched = false;
_prefabdesc.powerCoverRadius = _oldCoverRadius;
_prefabdesc.powerConnectDistance = _oldConnectDistance;
_patched = false;
}
// Iterate all factories and update wind turbines power nodes
if (GameMain.data == null) return;
foreach (var factory in GameMain.data.factories)
var factories = GameMain.data?.factories;
if (factories == null) return;
foreach (var factory in factories)
{
var powerSystem = factory?.powerSystem;
if (powerSystem == null) continue;