// Updates the stability of a block and returns false if the block has just been destroyed private bool UpdateStability(BuildingBlock block, bool propagate = true) { ++currentStats.blocksUpdated; if (block.isDestroyed) { #if DEBUG Log("Skipped " + BuildingBlockHelpers.Name(block) + ": Already destroyed"); #endif return(true); } // Log("Updating stability on " + block.Name()); // Exclude foundations from stability updates. if (BuildingBlockHelpers.IsFoundation(block)) { #if DEBUG Log("Skipped " + BuildingBlockHelpers.Name(block) + ": Is foundation"); #endif return(true); } List <BuildingBlock> supports; List <BuildingBlock> supported; BuildingBlockHelpers.GetAdjacentBlocks(block, out supports, out supported); if (supports.Count > 0) { #if DEBUG Log("Skipped " + BuildingBlockHelpers.Name(block) + ": Still has " + supports.Count + " supports"); #endif return(true); } // If this block has no more supports, destroy it. #if DEBUG Log(BuildingBlockHelpers.Name(block) + " has no (more) supports, killing (supported " + supported.Count + ")" + (propagate ? " - propagating" : " - not propagating")); #endif DemolishBlock(block); var deployables = BuildingBlockHelpers.GetOrphanedDeployables(block); foreach (var deployable in deployables) { if (!deployable.isDestroyed) { DemolishDeployable(deployable); } } if (propagate) { foreach (var supportedBlock in supported) { EnqueueUpdate(supportedBlock); } } return(false); }
private void OnServerInitialized() { LoadConfig(); var customMessages = (Dictionary <string, object>)Config["messages"]; if (customMessages != null) { foreach (var pair in customMessages) { messages[pair.Key] = Convert.ToString(pair.Value); } Log("Loaded " + customMessages.Count + " translation strings"); } // Initialize helpers BuildingBlockHelpers.Initialize(); // Force an update on all blocks when first started var fs = Interface.GetMod().DataFileSystem; var data = fs.GetDatafile("BetterStability"); bool firstStart = false; if (data["firststart"] == null) { Log("Starting the first time, forcing update on ALL blocks"); firstStart = true; data["firststart"] = false; fs.SaveDatafile("BetterStability"); } // Schedule stability updates for all blocks that support anything var allBlocks = UnityEngine.Object.FindObjectsOfType <BuildingBlock>(); int n = 0; foreach (var block in allBlocks) { if (firstStart || (!BuildingBlockHelpers.IsFoundation(block) && BuildingBlockHelpers.IsSupportForAnything(block))) { EnqueueUpdate(block); ++n; } } Log("Queued " + n + " blocks for stability updates"); }