public override void UpdateBeforeSimulation() { if (!MyAPIGateway.Session.IsServer) { return; } Runtime++; for (int i = requireSystem.Count - 1; i >= 0; i--) { WarpDrive drive = requireSystem [i]; if (drive.System == null || drive.System.InvalidOn <= Runtime - WarpConstants.groupSystemDelay) { requireSystem.RemoveAtFast(i); drive.SetWarpSystem(GetWarpSystem(drive)); } else if (HasValidSystem(drive)) { requireSystem.RemoveAtFast(i); } } for (int i = warpSystems.Count - 1; i >= 0; i--) { WarpSystem s = warpSystems [i]; if (s.Valid) { s.UpdateBeforeSimulation(); } else { warpSystems.RemoveAtFast(i); } } foreach (WarpSystem s in newSystems) { warpSystems.Add(s); } newSystems.Clear(); //MyVisualScriptLogicProvider.ShowNotification($"{warpSystems.Count} grids. {Runtime / 100}", 16); }
public WarpSystem(WarpDrive block, WarpSystem oldSystem) { Id = WarpDriveSession.Instance.Rand.Next(int.MinValue, int.MaxValue); grid = new GridSystem((MyCubeGrid)block.Block.CubeGrid); GridSystem.BlockCounter warpDriveCounter = new GridSystem.BlockCounter((b) => b?.GameLogic.GetAs <WarpDrive>() != null); warpDriveCounter.OnBlockAdded += OnDriveAdded; warpDriveCounter.OnBlockRemoved += OnDriveRemoved; grid.AddCounter("WarpDrives", warpDriveCounter); grid.OnSystemInvalidated += InvalidateSystem; if (oldSystem != null) { totalHeat = oldSystem.totalHeat; startWarpSource = oldSystem.startWarpSource; if (startWarpSource?.MarkedForClose == true) { startWarpSource = null; } WarpState = oldSystem.WarpState; if (WarpState == State.Charging) { UpdateEffect(WarpDriveSession.WarpEffectUpdate.State.Charging); startChargeRuntime = oldSystem.startChargeRuntime; WarpState = State.Charging; } else if (WarpState == State.Active) { //UpdateEffect(WarpDriveSession.WarpEffectUpdate.State.InWarp); currentSpeedPt = oldSystem.currentSpeedPt; WarpState = State.Active; } } block.SetWarpSystem(this); }
public void SetWarpSystem(WarpSystem system) { System = system; System.OnSystemInvalidated += OnSystemInvalidated; }