Beispiel #1
0
        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);
        }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            WarpDrive drive = obj as WarpDrive;

            return(drive != null &&
                   EqualityComparer <IMyFunctionalBlock> .Default.Equals(Block, drive.Block));
        }
Beispiel #3
0
        private bool GetWarpStatus(IMyTerminalBlock block)
        {
            WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>();

            if (!HasValidSystem(drive))
            {
                return(false);
            }
            return(drive.System.WarpState != WarpSystem.State.Idle);
        }
Beispiel #4
0
        private float GetWarpHeat(IMyTerminalBlock block)
        {
            WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>();

            if (!HasValidSystem(drive))
            {
                return(-1);
            }
            return(drive.System.HeatPercent);
        }
Beispiel #5
0
        private void SetWarpSafety(IMyTerminalBlock block, bool state)
        {
            WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>();

            if (!HasValidSystem(drive))
            {
                return;
            }
            drive.System.Safety = state;
        }
Beispiel #6
0
        private bool GetWarpSafety(IMyTerminalBlock block)
        {
            WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>();

            if (!HasValidSystem(drive))
            {
                return(false);
            }
            return(drive.System.Safety);
        }
Beispiel #7
0
        private void ToggleSafety(IMyTerminalBlock block)
        {
            WarpDrive drive = block?.GameLogic?.GetAs <WarpDrive>();

            if (!HasValidSystem(drive))
            {
                return;
            }
            drive.System.Safety = !drive.System.Safety;
        }
Beispiel #8
0
        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;
        }
Beispiel #9
0
        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");
            }
        }
Beispiel #10
0
        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);
                }
            }
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        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));
            }
        }
Beispiel #13
0
        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);
                }
            }
        }
Beispiel #14
0
        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;
            }
        }
Beispiel #15
0
        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);
        }
Beispiel #16
0
 public bool Contains(WarpDrive drive)
 {
     return(grid.Contains((MyCubeGrid)drive.Block.CubeGrid));
 }
Beispiel #17
0
 private bool HasValidSystem(WarpDrive drive)
 {
     return(drive?.System != null && drive.System.Valid);
 }
Beispiel #18
0
 public void DelayedGetWarpSystem(WarpDrive drive)
 {
     requireSystem.Add(drive);
 }