public WarpSystem GetWarpSystem(WarpDrive drive) { if (HasValidSystem(drive)) { return(drive.System); // Why are you here?!?! } foreach (WarpSystem s in warpSystems) { if (s.Valid && s.Contains(drive)) { return(s); } } foreach (WarpSystem s in newSystems) { if (s.Contains(drive)) { return(s); } } WarpSystem newSystem = new WarpSystem(drive, drive.System); newSystems.Add(newSystem); return(newSystem); }
public override bool Equals(object obj) { WarpDrive drive = obj as WarpDrive; return(drive != null && EqualityComparer <IMyFunctionalBlock> .Default.Equals(Block, drive.Block)); }
private bool GetWarpStatus(IMyTerminalBlock block) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return(false); } return(drive.System.WarpState != WarpSystem.State.Idle); }
private float GetWarpHeat(IMyTerminalBlock block) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return(-1); } return(drive.System.HeatPercent); }
private void SetWarpSafety(IMyTerminalBlock block, bool state) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return; } drive.System.Safety = state; }
private bool GetWarpSafety(IMyTerminalBlock block) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return(false); } return(drive.System.Safety); }
private void ToggleSafety(IMyTerminalBlock block) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return; } drive.System.Safety = !drive.System.Safety; }
private void OnDriveAdded(IMyCubeBlock block) { WarpDrive drive = block.GameLogic.GetAs <WarpDrive>(); drive.SetWarpSystem(this); HashSet <WarpDrive> gridDrives; if (!warpDrives.TryGetValue(block.CubeGrid, out gridDrives)) { gridDrives = new HashSet <WarpDrive>(); } gridDrives.Add(drive); warpDrives [block.CubeGrid] = gridDrives; }
private void GetSafetyText(IMyTerminalBlock block, StringBuilder s) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return; } if (drive.System.Safety) { s.Append("On"); } else { s.Append("Off"); } }
private void OnDriveRemoved(IMyCubeBlock block) { WarpDrive drive = block.GameLogic.GetAs <WarpDrive>(); HashSet <WarpDrive> gridDrives; if (warpDrives.TryGetValue(block.CubeGrid, out gridDrives)) { gridDrives.Remove(drive); if (gridDrives.Count > 0) { warpDrives [block.CubeGrid] = gridDrives; } else { warpDrives.Remove(block.CubeGrid); } } }
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); }
private void ToggleWarp(IMyTerminalBlock block) { if (MyAPIGateway.Session.IsServer) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return; } drive.System.ToggleWarp(block.CubeGrid); } else { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (drive == null) { return; } MyAPIGateway.Multiplayer.SendMessageToServer(packetToggleWarp, BitConverter.GetBytes(block.EntityId)); } }
private void SetWarpStatus(IMyTerminalBlock block, bool state) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return; } if (state) { if (drive.System.WarpState == WarpSystem.State.Idle) { drive.System.ToggleWarp(block.CubeGrid); } } else { if (drive.System.WarpState != WarpSystem.State.Idle) { drive.System.ToggleWarp(block.CubeGrid); } } }
private void GetWarpStatusText(IMyTerminalBlock block, StringBuilder s) { WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>(); if (!HasValidSystem(drive)) { return; } switch (drive.System.WarpState) { case WarpSystem.State.Charging: s.Append("-"); break; case WarpSystem.State.Active: s.Append("On"); break; case WarpSystem.State.Idle: s.Append("Off"); break; } }
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 bool Contains(WarpDrive drive) { return(grid.Contains((MyCubeGrid)drive.Block.CubeGrid)); }
private bool HasValidSystem(WarpDrive drive) { return(drive?.System != null && drive.System.Valid); }
public void DelayedGetWarpSystem(WarpDrive drive) { requireSystem.Add(drive); }