コード例 #1
0
        public bool Run(string machineName, long ownerId = 0)
        {
            MyObjectBuilder_ScriptSM ob;

            if (m_machineDefinitions.TryGetValue(machineName, out ob))
            {
                var machine = new MyVSStateMachine();
                machine.Init(ob, ownerId);
                m_runningMachines.Add(machine);
                if (MyVisualScriptLogicProvider.MissionStarted != null)
                {
                    MyVisualScriptLogicProvider.MissionStarted(machine.Name);
                }

                return(true);
            }

            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Creates new active cursor.
        /// </summary>
        public virtual MyStateMachineCursor CreateCursor(string nodeName)
        {
            var foundNode = FindNode(nodeName);

            if (foundNode != null)
            {
                var newCursor = new MyStateMachineCursor(foundNode, this);
                m_activeCursorsById.Add(newCursor.Id, newCursor);
                m_activeCursors.Add(newCursor);
                return(newCursor);
            }

            return(null);
        }
コード例 #3
0
        public void TryCreateObstacle(MyEntity newEntity)
        {
            if (newEntity.Physics == null)
            {
                return;
            }
            if (!(newEntity is MyCubeGrid))
            {
                return;
            }
            if (newEntity.PositionComp == null)
            {
                return;
            }

            var obstacle = MyObstacleFactory.CreateObstacleForEntity(newEntity);

            if (obstacle != null)
            {
                m_obstacles.Add(obstacle);
            }
        }
コード例 #4
0
        public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
        {
            base.Init(sessionComponent);

            // Only servers can run this session component
            if (!Session.IsServer)
            {
                return;
            }
            MyObjectBuilder_VisualScriptManagerSessionComponent ob = (MyObjectBuilder_VisualScriptManagerSessionComponent)sessionComponent;

            m_objectBuilder = ob;
            m_relativePathsToAbsolute.Clear();
            m_stateMachineDefinitionFilePaths.Clear();

            // Runs game started event
            m_firstUpdate = ob.FirstRun;

            // load vanilla level script files
            if (ob.LevelScriptFiles != null)
            {
                foreach (string relativeFilePath in ob.LevelScriptFiles)
                {
                    var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath);
                    // Add only existing files
                    if (MyFileSystem.FileExists(absolutePath))
                    {
                        m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(relativeFilePath + " Level Script was not found.");
                        Debug.Fail(relativeFilePath + " Level Script was not found.");
                    }
                }
            }

            // load vanilla mission manchines
            if (ob.StateMachines != null)
            {
                foreach (var relativeFilePath in ob.StateMachines)
                {
                    var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath);
                    // Add only existing files
                    if (MyFileSystem.FileExists(absolutePath))
                    {
                        if (!m_relativePathsToAbsolute.ContainsKey(relativeFilePath))
                        {
                            m_stateMachineDefinitionFilePaths.Add(absolutePath);
                        }

                        m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(relativeFilePath + " Mission File was not found.");
                        Debug.Fail(relativeFilePath + " Mission File was not found.");
                    }
                }
            }

            // Load mission machines and level scripts from mods
            // Overrides vanilla files
            if (Session.Mods != null)
            {
                foreach (var modItem in Session.Mods)
                {
                    // First try is a mod archive
                    var directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.PublishedFileId + ".sbm");
                    if (!MyFileSystem.DirectoryExists(directoryPath))
                    {
                        directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.Name);
                        if (!MyFileSystem.DirectoryExists(directoryPath))
                        {
                            directoryPath = null;
                        }
                    }

                    if (!string.IsNullOrEmpty(directoryPath))
                    {
                        foreach (var filePath in MyFileSystem.GetFiles(directoryPath, "*", MySearchOption.AllDirectories))
                        {
                            var extension    = Path.GetExtension(filePath);
                            var relativePath = MyFileSystem.MakeRelativePath(Path.Combine(directoryPath, "VisualScripts"), filePath);
                            if (extension == ".vs" || extension == ".vsc")
                            {
                                if (m_relativePathsToAbsolute.ContainsKey(relativePath))
                                {
                                    m_relativePathsToAbsolute[relativePath] = filePath;
                                }
                                else
                                {
                                    m_relativePathsToAbsolute.Add(relativePath, filePath);
                                }
                            }
                        }
                    }
                }
            }

            // Provider will compile all required scripts for the session.
            MyVSAssemblyProvider.Init(m_relativePathsToAbsolute.Values);
            // Retrive the Level script instances
            m_levelScripts = new CachingList <IMyLevelScript>();
            var scriptInstances = MyVSAssemblyProvider.GetLevelScriptInstances();

            if (scriptInstances != null)
            {
                scriptInstances.ForEach(script => m_levelScripts.Add(script));
            }
            m_levelScripts.ApplyAdditions();

            // Store the names of the level scripts
            m_runningLevelScriptNames         = m_levelScripts.Select(x => x.GetType().Name).ToArray();
            m_failedLevelScriptExceptionTexts = new string[m_runningLevelScriptNames.Length];

            // mission manager initialization - state machine definitions
            m_smManager = new MyVSStateMachineManager();
            foreach (var stateMachineFilePath in m_stateMachineDefinitionFilePaths)
            {
                m_smManager.AddMachine(stateMachineFilePath);
            }
        }
コード例 #5
0
        public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
        {
            base.Init(sessionComponent);

            // Only servers can run this session component
            if(!Session.IsServer) return;
            MyObjectBuilder_VisualScriptManagerSessionComponent ob = (MyObjectBuilder_VisualScriptManagerSessionComponent) sessionComponent;
            m_objectBuilder = ob;
            m_relativePathsToAbsolute.Clear();
            m_stateMachineDefinitionFilePaths.Clear();

            // Runs game started event
            m_firstUpdate = ob.FirstRun;

            // load vanilla level script files
            if (ob.LevelScriptFiles != null)
                foreach (string relativeFilePath in ob.LevelScriptFiles)
                {
                    var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath);
                    // Add only existing files
                    if(MyFileSystem.FileExists(absolutePath))
                    {
                        m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(relativeFilePath + " Level Script was not found.");
                        Debug.Fail(relativeFilePath + " Level Script was not found.");
                    }
                }

            // load vanilla mission manchines
            if(ob.StateMachines != null)
                foreach (var relativeFilePath in ob.StateMachines)
                {
                    var absolutePath = Path.Combine(MyFileSystem.ContentPath, relativeFilePath);
                    // Add only existing files
                    if (MyFileSystem.FileExists(absolutePath))
                    {
                        if (!m_relativePathsToAbsolute.ContainsKey(relativeFilePath))
                        {
                            m_stateMachineDefinitionFilePaths.Add(absolutePath);
                        }

                        m_relativePathsToAbsolute.Add(relativeFilePath, absolutePath);
                    }
                    else
                    {
                        MyLog.Default.WriteLine(relativeFilePath + " Mission File was not found.");
                        Debug.Fail(relativeFilePath + " Mission File was not found.");
                    }
                }

            // Load mission machines and level scripts from mods
            // Overrides vanilla files
            if(Session.Mods != null)
            {
                foreach (var modItem in Session.Mods)
                {
                    // First try is a mod archive
                    var directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.PublishedFileId + ".sbm");
                    if (!MyFileSystem.DirectoryExists(directoryPath))
                    {
                        directoryPath = Path.Combine(MyFileSystem.ModsPath, modItem.Name);
                        if(!MyFileSystem.DirectoryExists(directoryPath))
                            directoryPath = null;
                    }

                    if (!string.IsNullOrEmpty(directoryPath))
                    {
                        foreach (var filePath in MyFileSystem.GetFiles(directoryPath, "*", MySearchOption.AllDirectories))
                        {
                            var extension = Path.GetExtension(filePath);
                            var relativePath = MyFileSystem.MakeRelativePath(Path.Combine(directoryPath, "VisualScripts"), filePath);
                            if (extension == ".vs" || extension == ".vsc")
                            {
                                if(m_relativePathsToAbsolute.ContainsKey(relativePath))
                                    m_relativePathsToAbsolute[relativePath] = filePath;
                                else
                                    m_relativePathsToAbsolute.Add(relativePath, filePath);
                            }
                        }
                    }
                }
            }

            // Provider will compile all required scripts for the session.
            MyVSAssemblyProvider.Init(m_relativePathsToAbsolute.Values);
            // Retrive the Level script instances
            m_levelScripts = new CachingList<IMyLevelScript>();
            var scriptInstances = MyVSAssemblyProvider.GetLevelScriptInstances();
            if(scriptInstances != null)
            {
                scriptInstances.ForEach(script => m_levelScripts.Add(script));
            }
            m_levelScripts.ApplyAdditions();

            // Store the names of the level scripts
            m_runningLevelScriptNames = m_levelScripts.Select(x => x.GetType().Name).ToArray();
            m_failedLevelScriptExceptionTexts = new string[m_runningLevelScriptNames.Length];

            // mission manager initialization - state machine definitions
            m_smManager = new MyVSStateMachineManager();
            foreach (var stateMachineFilePath in m_stateMachineDefinitionFilePaths)
            {
                m_smManager.AddMachine(stateMachineFilePath);
            }
        }
コード例 #6
0
        private void Arm()
        {
            if (!ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowWeaponControl))
            {
                Log.DebugLog("Cannot arm, weapon control is disabled.", Logger.severity.WARNING);
                return;
            }

            Log.DebugLog("Arming", Logger.severity.DEBUG);

            Log.DebugLog("Fixed weapons has not been cleared", Logger.severity.FATAL, condition: m_weapons_fixed.Count != 0);
            Log.DebugLog("All weapons has not been cleared", Logger.severity.FATAL, condition: m_weapons_all.Count != 0);

            m_weaponRange_min = float.MaxValue;

            CubeGridCache cache = CubeGridCache.GetFor(m_controlBlock.CubeGrid);

            foreach (FixedWeapon weapon in Registrar.Scripts <FixedWeapon, WeaponTargeting>())
            {
                if (weapon.CubeBlock.CubeGrid == m_controlBlock.CubeGrid)
                {
                    if (weapon.EngagerTakeControl())
                    {
                        Log.DebugLog("Took control of " + weapon.CubeBlock.DisplayNameText);
                        m_weapons_fixed.Add(weapon);
                        m_weapons_all.Add(weapon);

                        weapon.CubeBlock.OnClosing += Weapon_OnClosing;
                    }
                    else
                    {
                        Log.DebugLog("failed to get control of: " + weapon.CubeBlock.DisplayNameText);
                    }
                }
                if (weapon.MotorTurretBaseGrid() == m_controlBlock.CubeGrid)
                {
                    Log.DebugLog("Active motor turret: " + weapon.CubeBlock.DisplayNameText);
                    m_weapons_all.Add(weapon);

                    weapon.CubeBlock.OnClosing += Weapon_OnClosing;
                }
            }

            foreach (MyObjectBuilderType weaponType in TurretWeaponTypes)
            {
                foreach (IMyCubeBlock block in cache.BlocksOfType(weaponType))
                {
                    WeaponTargeting weapon;
                    if (!Registrar.TryGetValue(block.EntityId, out weapon))
                    {
                        Logger.AlwaysLog("Failed to get block: " + block.nameWithId(), Logger.severity.WARNING);
                        continue;
                    }
                    if (weapon.CurrentControl != WeaponTargeting.Control.Off)
                    {
                        Log.DebugLog("Active turret: " + weapon.CubeBlock.DisplayNameText);
                        m_weapons_all.Add(weapon);

                        weapon.CubeBlock.OnClosing += Weapon_OnClosing;
                    }
                }
            }

            m_weapons_fixed.ApplyAdditions();
            m_weapons_all.ApplyAdditions();

            m_weaponArmed     = m_weapons_all.Count != 0;
            m_weaponDataDirty = m_weaponArmed;
            if (m_weaponArmed)
            {
                Log.DebugLog("Now armed", Logger.severity.DEBUG);
            }
            else
            {
                Log.DebugLog("Failed to arm", Logger.severity.DEBUG);
            }
        }