private void LoadSaveData(Builder_ArmsData data) { if (data == null) { Logger.DebugLog("No data to load"); return; } #pragma warning disable 612, 618 if (Comparer <Version> .Default.Compare(data.ArmsVersion, default(Version)) == 0) { Logger.DebugLog("Old version: " + data.ModVersion); data.ArmsVersion = new Version(data.ModVersion); } #pragma warning restore 612, 618 Logger.AlwaysLog("Save version: " + data.ArmsVersion, Rynchodon.Logger.severity.INFO); // relay Dictionary <Message.Builder_Message, Message> messages = MyAPIGateway.Multiplayer.IsServer ? new Dictionary <Message.Builder_Message, Message>() : null; SerializableGameTime.Adjust = new TimeSpan(data.SaveTime); foreach (RelayStorage.Builder_NetworkStorage bns in data.AntennaStorage) { RelayNode node; if (!Registrar.TryGetValue(bns.PrimaryNode, out node)) { Logger.AlwaysLog("Failed to get node for: " + bns.PrimaryNode, Rynchodon.Logger.severity.WARNING); continue; } RelayStorage store = node.Storage; if (store == null) // probably always true { node.ForceCreateStorage(); store = node.Storage; if (store == null) { Logger.AlwaysLog("failed to create storage for " + node.DebugName, Rynchodon.Logger.severity.ERROR); continue; } } foreach (LastSeen.Builder_LastSeen bls in bns.LastSeenList) { LastSeen ls = new LastSeen(bls); if (ls.IsValid) { store.Receive(ls); } else { Logger.AlwaysLog("failed to create a valid last seen from builder for " + bls.EntityId, Rynchodon.Logger.severity.WARNING); if (m_failedLastSeen == null) { m_failedLastSeen = new CachingDictionary <long, CachingList <LastSeen.Builder_LastSeen> >(); UpdateManager.Register(100, RetryLastSeen); } CachingList <LastSeen.Builder_LastSeen> list; if (!m_failedLastSeen.TryGetValue(bns.PrimaryNode, out list)) { list = new CachingList <LastSeen.Builder_LastSeen>(); m_failedLastSeen.Add(bns.PrimaryNode, list, true); } list.Add(bls); list.ApplyAdditions(); } } Logger.DebugLog("added " + bns.LastSeenList.Length + " last seen to " + store.PrimaryNode.DebugName, Rynchodon.Logger.severity.DEBUG); // messages in the save file belong on the server if (messages == null) { continue; } foreach (Message.Builder_Message bm in bns.MessageList) { Message msg; if (!messages.TryGetValue(bm, out msg)) { msg = new Message(bm); messages.Add(bm, msg); } else { Logger.DebugLog("found linked message", Rynchodon.Logger.severity.TRACE); } if (msg.IsValid) { store.Receive(msg); } else { Logger.AlwaysLog("failed to create a valid message from builder for " + bm.DestCubeBlock + "/" + bm.SourceCubeBlock, Rynchodon.Logger.severity.WARNING); } } Logger.DebugLog("added " + bns.MessageList.Length + " message to " + store.PrimaryNode.DebugName, Rynchodon.Logger.severity.DEBUG); } // past this point, only synchronized data if (!MyAPIGateway.Multiplayer.IsServer) { data = null; return; } // system disruption foreach (Disruption.Builder_Disruption bd in data.SystemDisruption) { Disruption disrupt; switch (bd.Type) { case "AirVentDepressurize": disrupt = new AirVentDepressurize(); break; case "CryoChamberMurder": disrupt = new CryoChamberMurder(); break; case "DisableTurret": disrupt = new DisableTurret(); break; case "DoorLock": disrupt = new DoorLock(); break; case "EMP": disrupt = new EMP(); break; case "GravityReverse": disrupt = new GravityReverse(); break; case "JumpDriveDrain": disrupt = new JumpDriveDrain(); break; case "MedicalRoom": disrupt = new MedicalRoom(); break; case "TraitorTurret": disrupt = new TraitorTurret(); break; default: Logger.AlwaysLog("Unknown disruption: " + bd.Type, Rynchodon.Logger.severity.WARNING); continue; } disrupt.Start(bd); } // autopilot if (data.Autopilot != null) { foreach (ShipAutopilot.Builder_Autopilot ba in data.Autopilot) { ShipAutopilot autopilot; if (Registrar.TryGetValue(ba.AutopilotBlock, out autopilot)) { autopilot.ResumeFromSave(ba); } else { Logger.AlwaysLog("failed to find autopilot block " + ba.AutopilotBlock, Rynchodon.Logger.severity.WARNING); } } } // programmable block if (data.ProgrammableBlock != null) { foreach (ProgrammableBlock.Builder_ProgrammableBlock bpa in data.ProgrammableBlock) { ProgrammableBlock pb; if (Registrar.TryGetValue(bpa.BlockId, out pb)) { pb.ResumeFromSave(bpa); } else { Logger.AlwaysLog("failed to find programmable block " + bpa.BlockId, Rynchodon.Logger.severity.WARNING); } } } // text panel if (data.TextPanel != null) { foreach (TextPanel.Builder_TextPanel btp in data.TextPanel) { TextPanel panel; if (Registrar.TryGetValue(btp.BlockId, out panel)) { panel.ResumeFromSave(btp); } else { Logger.AlwaysLog("failed to find text panel " + btp.BlockId, Rynchodon.Logger.severity.WARNING); } } } // weapon if (data.Weapon != null) { foreach (WeaponTargeting.Builder_WeaponTargeting bwt in data.Weapon) { WeaponTargeting targeting; if (WeaponTargeting.TryGetWeaponTargeting(bwt.WeaponId, out targeting)) { targeting.ResumeFromSave(bwt); } else { Logger.AlwaysLog("failed to find weapon " + bwt.WeaponId, Rynchodon.Logger.severity.WARNING); } } } // entity values if (data.EntityValues != null) { UpgradeEntityValue.Load(data.EntityValues); } // sync if (data.Sync != null) { ASync.SetBuilder(data.Sync); } data = null; }