Example #1
0
    private void UnlockFromMouse()
    {
        _lockToMouse    = false;
        _mouseSnapPoint = transform.position;

        CurrentlyMovingProgrammableBlock = null;
    }
Example #2
0
    /// <summary>
    /// Gets a connected ProgrammableBlock from a given Direction.
    /// </summary>
    /// <param name="direction">The direction of the connected block.</param>
    /// <returns>The connected block in a given Direction.</returns>
    public ProgrammableBlock GetConnectedProgrammableBlock(Direction direction)
    {
        ProgrammableBlock connectedProgrammableBlock = null;

        try
        {
            switch (direction)
            {
            case Direction.Left:
                connectedProgrammableBlock = SnappingPoints.left.snapPoint.ConnectedSnapPoint.ProgrammableBlock;
                break;

            case Direction.Right:
                connectedProgrammableBlock = SnappingPoints.right.snapPoint.ConnectedSnapPoint.ProgrammableBlock;
                break;

            case Direction.Up:
                connectedProgrammableBlock = SnappingPoints.up.snapPoint.ConnectedSnapPoint.ProgrammableBlock;
                break;

            case Direction.Down:
                connectedProgrammableBlock = SnappingPoints.down.snapPoint.ConnectedSnapPoint.ProgrammableBlock;
                break;
            }
        }
        catch
        {
            return(null);
        }

        return(connectedProgrammableBlock);
    }
Example #3
0
    private void AddOutline(ProgrammableBlock programmableBlock)
    {
        Outline outline = programmableBlock.Image.gameObject.AddComponent <Outline>();

        outline.effectColor    = Color.black;
        outline.effectDistance = new Vector2(3, -3);
    }
Example #4
0
        /// <summary>
        /// Scripts that use UpdateManager shall be added here.
        /// </summary>
        private void RegisterScripts()
        {
            RegisterForBlock(typeof(MyObjectBuilder_Beacon), (IMyCubeBlock block) =>
            {
                Beacon newBeacon = new Beacon(block);
                RegisterForUpdates(100, newBeacon.UpdateAfterSimulation100, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_TextPanel), (IMyCubeBlock block) =>
            {
                TextPanel newTextPanel = new TextPanel(block);
                RegisterForUpdates(100, newTextPanel.UpdateAfterSimulation100, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), (IMyCubeBlock block) =>
            {
                LaserAntenna newLA = new LaserAntenna(block);
                RegisterForUpdates(100, newLA.UpdateAfterSimulation100, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), (IMyCubeBlock block) =>
            {
                ProgrammableBlock newPB = new ProgrammableBlock(block);
                RegisterForUpdates(100, newPB.UpdateAfterSimulation100, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (IMyCubeBlock block) =>
            {
                RadioAntenna newRA = new RadioAntenna(block);
                RegisterForUpdates(100, newRA.UpdateAfterSimulation100, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), (IMyCubeBlock block) =>
            {
                RemoteControl newRC = new RemoteControl(block);
                // Does not receive Updates
            });

            RegisterForBlock(typeof(MyObjectBuilder_LargeGatlingTurret), (IMyCubeBlock block) =>
            {
                TurretLargeGatling newTurret = new TurretLargeGatling(block);
                RegisterForUpdates(1, newTurret.UpdateAfterSimulation, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_LargeMissileTurret), (IMyCubeBlock block) =>
            {
                TurretLargeRocket newTurret = new TurretLargeRocket(block);
                RegisterForUpdates(1, newTurret.UpdateAfterSimulation, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_InteriorTurret), (IMyCubeBlock block) =>
            {
                TurretInterior newTurret = new TurretInterior(block);
                RegisterForUpdates(1, newTurret.UpdateAfterSimulation, block);
            });

            //RegisterForBlock(typeof(MyObjectBuilder_OreDetector), (IMyCubeBlock block) =>
            //	{
            //		OreDetector newOD = new OreDetector(block);
            //		RegisterForUpdates(100, newOD.Update100, block);
            //	});
        }
Example #5
0
    private void LockToMouse()
    {
        _audioSource.clip = _clickClip;
        _audioSource.Play();

        if (tag == "StartNode")
        {
            return;
        }

        _lockToMouse    = true;
        _mouseSnapPoint = transform.position;

        transform.SetAsLastSibling();

        CurrentlyMovingProgrammableBlock = this;
    }
Example #6
0
    /// <summary>
    /// Executes all connected blocks.
    /// </summary>
    public override void Execute()
    {
        if (_isRunning)
        {
            return;
        }

        _currentProgrammableBlock = programmableBlock.GetConnectedProgrammableBlock(ProgrammableBlock.Direction.Down);

        if (!_currentProgrammableBlock)
        {
            OnFinish.Invoke();
            return;
        }

        _isRunning = true;
        StartCoroutine(ExecutionRoutine());
    }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Program"/> class.
        /// </summary>
        public Program()
        {
            // init echo wrapper
            EchoR = log =>
            {
                echoOutput.AppendLine(log);
                Echo(log);
            };

            // init settings
            RetrieveCustomSetting();

            // initialise the process steps we will need to do
            processSteps = new Action[]
            {
                ProcessStepCheckBroadcastMessages,
                ProcessStepDetectGridsUsingSensor,
                ProcessStepDetectGridsUsingCamera,
                ProcessStepCleanDetectedEntities
            };

            Runtime.UpdateFrequency = FREQUENCY;

            CelestialMap      = new Map(this, celestialBodies);
            programmableBlock = new ProgrammableBlock(this);
            shipController    = new ShipController(this);
            textPanel         = new DisplayTerminal(this, CelestialMap);

            this.BroadcastListener = this.IGC.RegisterBroadcastListener(GpsBroadcastTag);
            this.BroadcastListener.SetMessageCallback();

            terminalCycle = SetTerminalCycle();

            EchoR(string.Format("Compiled {0} {1}", SCRIPT_NAME, VERSION_NICE_TEXT));

            // format terminal info text
            scriptUpdateText = string.Format(FORMAT_UPDATE_TEXT, SCRIPT_NAME, VERSION_NICE_TEXT);
        }
Example #8
0
    private IEnumerator ExecutionRoutine()
    {
        while (true)
        {
            AddOutline(_currentProgrammableBlock);
            DecisionLogic logic = _currentProgrammableBlock.GetComponent <DecisionLogic>();

            if (!logic)
            {
                yield return(null);
            }

            yield return(new WaitForSeconds(1));

            RemoveOutline(_currentProgrammableBlock);

            if (logic.Decide())
            {
                #region Execute Actions

                ProgrammableBlock tempProgrammableBlock = _currentProgrammableBlock;
                ExecutionLogic    executionLogic        = null;

                while (true)
                {
                    tempProgrammableBlock = tempProgrammableBlock.GetConnectedProgrammableBlock(ProgrammableBlock.Direction.Right);

                    if (!tempProgrammableBlock)
                    {
                        break;
                    }

                    executionLogic = tempProgrammableBlock.GetComponent <ExecutionLogic>();
                    AddOutline(tempProgrammableBlock);

                    if (!executionLogic)
                    {
                        yield return(new WaitForSeconds(1));

                        RemoveOutline(tempProgrammableBlock);
                        continue;
                    }

                    executionLogic.Execute();

                    yield return(new WaitForSeconds(1));

                    RemoveOutline(tempProgrammableBlock);
                }

                #endregion
            }

            _currentProgrammableBlock = _currentProgrammableBlock.GetConnectedProgrammableBlock(ProgrammableBlock.Direction.Down);

            if (!_currentProgrammableBlock)
            {
                break;
            }
        }

        _isRunning = false;
        OnFinish.Invoke();

        yield return(null);
    }
Example #9
0
 private void RemoveOutline(ProgrammableBlock programmableBlock)
 {
     Destroy(programmableBlock.Image.GetComponent <Outline>());
 }
 private void Awake()
 {
     programmableBlock = GetComponent <ProgrammableBlock>();
 }
Example #11
0
        public Program()
        {
            // ---------------------------------------------------------------
            // Celestial bodies - Start.
            celestialBodies = new List <CelestialBody>()
            {
                new CelestialBody
                {
                    Name          = "EarthLike",
                    Radius        = 60000,
                    Gravity       = 1,
                    HasAtmosphere = true,
                    Oxygen        = Oxygen.High,
                    Type          = CelestialType.Planet,
                    Position      = new Vector3(0.5f, 0.5f, 0.5f),
                    Resources     = "All"
                },
                new CelestialBody
                {
                    Name          = "Moon",
                    Radius        = 9500,
                    Gravity       = 0.25f,
                    HasAtmosphere = false,
                    Oxygen        = Oxygen.None,
                    Type          = CelestialType.Moon,
                    Position      = new Vector3(16384.5f, 136384.5f, -113615.5f),
                    Resources     = "All"
                },
                new CelestialBody
                {
                    Name          = "Mars",
                    Radius        = 60000,
                    Gravity       = 0.9f,
                    HasAtmosphere = true,
                    Oxygen        = Oxygen.None,
                    Type          = CelestialType.Planet,
                    Position      = new Vector3(1031072.5f, 131072.5f, 1631072.5f),
                    Resources     = "All"
                },
                new CelestialBody
                {
                    Name          = "Europa",
                    Radius        = 9500,
                    Gravity       = 0.25f,
                    HasAtmosphere = true,
                    Oxygen        = Oxygen.None,
                    Type          = CelestialType.Moon,
                    Position      = new Vector3(916384.5f, 16384.5f, 1616384.5f),
                    Resources     = "All"
                },
                new CelestialBody
                {
                    Name          = "Alien",
                    Radius        = 60000,
                    Gravity       = 1.1f,
                    HasAtmosphere = true,
                    Oxygen        = Oxygen.Low,
                    Type          = CelestialType.Planet,
                    Position      = new Vector3(131072.5f, 131072.5f, 5731072.5f),
                    Resources     = "All"
                },
                //new CelestialBody
                //{
                //	Name = "Alien2",
                //	Radius = 60000,
                //	Gravity = 1.1f,
                //	HasAtmosphere = true,
                //	Oxygen = Oxygen.Low,
                //	Type = CelestialType.Planet,
                //	Position = new Vector3(131072.5f, 131072.5f, -4731072.5f),
                //	Resources = "All"
                //},
                //new CelestialBody
                //{
                //	Name = "Alien3",
                //	Radius = 60000,
                //	Gravity = 1.1f,
                //	HasAtmosphere = true,
                //	Oxygen = Oxygen.Low,
                //	Type = CelestialType.Planet,
                //	Position = new Vector3(-831072.5f, 131072.5f, -8731072.5f),
                //	Resources = "All"
                //},
                new CelestialBody
                {
                    Name          = "Titan",
                    Radius        = 9500,
                    Gravity       = 0.25f,
                    HasAtmosphere = true,
                    Oxygen        = Oxygen.None,
                    Type          = CelestialType.Moon,
                    Position      = new Vector3(36384.5f, 226384.5f, 5796384.5f),
                    Resources     = "All"
                }

                /*,
                 * new CelestialBody
                 * {
                 *      Name = "Triton",
                 *      Radius = 40126.5f,
                 *      Gravity = 1,
                 *      HasAtmosphere = true,
                 *      Oxygen = Oxygen.High,
                 *      Type = CelestialType.Planet,
                 *      Position = new Vector3(-284463.5f, -2434463.5, 365536.5f),
                 *      Resources = "All"
                 * }
                 */
            };
            // Celestial bodies - End.
            // ---------------------------------------------------------------

            programmableBlock = new ProgrammableBlock(this, FREQUENCY);
            world             = new World(this);
            terminalManager   = new TerminalManager(this);
        }
Example #12
0
        /// <summary>
        /// Scripts that use UpdateManager and run on clients as well as on server shall be added here.
        /// </summary>
        private void RegisterScripts_ClientAndServer()
        {
            #region Attached

            RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_MotorStator), typeof(MyObjectBuilder_MotorAdvancedStator), typeof(MyObjectBuilder_MotorSuspension) },
                             block => RegisterForUpdates(100, (new StatorRotor.Stator(block)).Update, block));

            RegisterForBlock(typeof(MyObjectBuilder_ExtendedPistonBase), (block) => {
                Piston.PistonBase pistonBase = new Piston.PistonBase(block);
                RegisterForUpdates(100, pistonBase.Update, block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_ShipConnector), (block) => {
                Connector conn = new Connector(block);
                RegisterForUpdates(10, conn.Update, block);
            });

            RegisterForBlock(typeof(MyObjectBuilder_LandingGear), (block) => {
                if (!Hacker.IsHacker(block))
                {
                    new LandingGear(block);
                }
            });

            #endregion

            #region Antenna Communication

            Action <IMyCubeBlock> nodeConstruct = block => {
                RelayNode node = new RelayNode(block);
                RegisterForUpdates(100, node.Update100, block);
            };

            RegisterForBlock(typeof(MyObjectBuilder_Beacon), nodeConstruct);
            RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), nodeConstruct);
            RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), nodeConstruct);

            RegisterForCharacter(character => {
                if (character.IsPlayer)
                {
                    RelayNode node = new RelayNode(character);
                    RegisterForUpdates(100, node.Update100, (IMyEntity)character);
                }
            });

            RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), block => {
                ProgrammableBlock pb = new ProgrammableBlock(block);
                if (MyAPIGateway.Multiplayer.IsServer)
                {
                    RegisterForUpdates(100, pb.Update100, block);
                }
            });

            RegisterForBlock(typeof(MyObjectBuilder_TextPanel), block => {
                TextPanel tp = new TextPanel(block);
                if (MyAPIGateway.Multiplayer.IsServer)
                {
                    RegisterForUpdates(100, tp.Update100, block);
                }
            });

            RegisterForBlock(typeof(MyObjectBuilder_Projector), block => {
                Projector p = new Projector(block);
                if (MyAPIGateway.Session.Player != null)
                {
                    RegisterForUpdates(100, p.Update100, block);
                    RegisterForUpdates(1, p.Update1, block);
                }
            });

            if (MyAPIGateway.Session.Player != null)
            {
                new Player();
            }

            #endregion

            #region Autopilot

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                //RadarEquipment.Definition apRadar = new RadarEquipment.Definition()
                //{
                //	Radar = true,
                //	LineOfSight = false,
                //	MaxTargets_Tracking = 3,
                //	MaxPowerLevel = 1000
                //};

                Action <IMyCubeBlock> apConstruct = (block) => {
                    if (ShipAutopilot.IsAutopilotBlock(block))
                    {
                        nodeConstruct(block);
                        new AutopilotTerminal(block);
                        //RadarEquipment r = new RadarEquipment(block, apRadar, block);
                        //RegisterForUpdates(100, r.Update100, block);
                    }
                };

                if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bUseRemoteControl))
                {
                    RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), apConstruct);
                }
                RegisterForBlock(typeof(MyObjectBuilder_Cockpit), apConstruct);
            }

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAirResistanceBeta))
            {
                RegisterForGrid(grid => {
                    AeroEffects aero = new AeroEffects(grid);
                    RegisterForUpdates(1, aero.Update1, grid);
                    if (MyAPIGateway.Multiplayer.IsServer)
                    {
                        RegisterForUpdates(100, aero.Update100, grid);
                    }
                });
                RegisterForBlock(typeof(MyObjectBuilder_Cockpit), block => RegisterForUpdates(1, (new CockpitTerminal(block)).Update1, block));
            }

            #endregion

            #region Radar

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowRadar))
            {
                RegisterForBlock(typeof(MyObjectBuilder_Beacon), (block) => {
                    if (RadarEquipment.IsDefinedRadarEquipment(block))
                    {
                        new RadarEquipment(block);
                    }
                });
                RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (block) => {
                    if (RadarEquipment.IsDefinedRadarEquipment(block))
                    {
                        new RadarEquipment(block);
                    }
                });
                RegisterForUpdates(100, RadarEquipment.UpdateAll);
            }

            #endregion

            #region Terminal Control

            RegisterForBlock(new MyObjectBuilderType[] { typeof(MyObjectBuilder_RadioAntenna), typeof(MyObjectBuilder_LaserAntenna) }, block => new ManualMessage(block));

            #endregion Terminal Control

            #region Weapon Control

            if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowWeaponControl))
            {
                #region Turrets

                Action <IMyCubeBlock> constructor;
                if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile))
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        Turret t = new Turret(block);
                        RegisterForUpdates(1, t.Update_Targeting, block);
                        if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
                        {
                            GuidedMissileLauncher gml = new GuidedMissileLauncher(t);
                            RegisterForUpdates(1, gml.Update1, block);
                        }
                    }
                }
                ;
                else
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        Turret t = new Turret(block);
                        RegisterForUpdates(1, t.Update_Targeting, block);
                    }
                };

                RegisterForBlock(typeof(MyObjectBuilder_LargeGatlingTurret), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_LargeMissileTurret), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_InteriorTurret), constructor);

                #endregion

                #region Fixed

                if (ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowGuidedMissile))
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        FixedWeapon w = new FixedWeapon(block);
                        RegisterForUpdates(1, w.Update_Targeting, block);
                        if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
                        {
                            GuidedMissileLauncher gml = new GuidedMissileLauncher(w);
                            RegisterForUpdates(1, gml.Update1, block);
                        }
                    };
                }
                else
                {
                    constructor = block => {
                        if (!WeaponTargeting.ValidWeaponBlock(block))
                        {
                            return;
                        }
                        FixedWeapon w = new FixedWeapon(block);
                        RegisterForUpdates(1, w.Update_Targeting, block);
                    }
                };

                RegisterForBlock(typeof(MyObjectBuilder_SmallGatlingGun), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncher), constructor);
                RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncherReload), constructor);

                #endregion

                // apparently missiles do not have their positions synced
                RegisterForUpdates(1, GuidedMissile.Update1);
                RegisterForUpdates(10, GuidedMissile.Update10);
                RegisterForUpdates(100, GuidedMissile.Update100);
            }
            else
            {
                Log.DebugLog("Weapon Control is disabled", Logger.severity.INFO);
            }

            #endregion

            #region Solar

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => new Solar(block));
                RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => new Solar(block));
            }

            #endregion

            new ChatHandler();
            Globals.Update100();
            RegisterForUpdates(100, Globals.Update100);

            Action <IMyCubeBlock> act = (block) => MainCockpitFix.AddController((IMyShipController)block);
            RegisterForBlock(typeof(MyObjectBuilder_Cockpit), act);
            RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), act);
        }