コード例 #1
0
        public override void UpdateBeforeSimulation()
        {
            // Only servers can run this session component
            if (!Session.IsServer)
            {
                return;
            }

            if (m_smManager != null)
            {
                m_smManager.Update();
            }

            if (m_levelScripts == null)
            {
                return;
            }
            foreach (var levelScript in m_levelScripts)
            {
                try
                {
                    if (m_firstUpdate)
                    {
                        levelScript.GameStarted();
                    }
                    else
                    {
                        levelScript.Update();
                    }
                }
                catch (Exception e)
                {
                    var brokenScriptName = levelScript.GetType().Name;
                    for (int index = 0; index < m_runningLevelScriptNames.Length; index++)
                    {
                        if (m_runningLevelScriptNames[index] == brokenScriptName)
                        {
                            m_runningLevelScriptNames[index]        += " - failed";
                            m_failedLevelScriptExceptionTexts[index] = e.ToString();
                        }
                    }

                    m_levelScripts.Remove(levelScript);
                }
            }

            m_levelScripts.ApplyRemovals();
            m_firstUpdate = false;
        }
コード例 #2
0
        /// <summary>
        /// Finds a primary weapon for m_weapon_primary and m_weapon_primary_pseudo.
        /// A primary weapon can be any working weapon with ammo.
        /// Preference is given to fixed weapons and weapons with targets.
        /// If no weapons have ammo, m_weapon_primary and m_weapon_primary_pseudo will be null.
        /// </summary>
        private void GetPrimaryWeapon()
        {
            if (m_weapon_primary != null && m_weapon_primary.CubeBlock.IsWorking && m_weapon_primary.CurrentTarget.Entity != null)
            {
                return;
            }

            WeaponTargeting weapon_primary = null;

            bool removed = false;

            foreach (FixedWeapon weapon in m_weapons_fixed)
            {
                if (weapon.CubeBlock.IsWorking)
                {
                    if (weapon.HasAmmo)
                    {
                        weapon_primary = weapon;
                        if (weapon.CurrentTarget.Entity != null)
                        {
                            Log.DebugLog("has target: " + weapon.CubeBlock.DisplayNameText);
                            break;
                        }
                    }
                    else
                    {
                        Log.DebugLog("no ammo: " + weapon.CubeBlock.DisplayNameText);
                    }
                }
                else
                {
                    Log.DebugLog("not working: " + weapon.CubeBlock.DisplayNameText);
                    m_weapons_fixed.Remove(weapon);
                    weapon.EngagerReleaseControl();
                    removed = true;
                }
            }

            if (weapon_primary == null)
            {
                foreach (WeaponTargeting weapon in m_weapons_all)
                {
                    if (weapon.CubeBlock.IsWorking)
                    {
                        if (weapon.HasAmmo)
                        {
                            weapon_primary = weapon;
                            if (weapon.CurrentTarget.Entity != null)
                            {
                                Log.DebugLog("has target: " + weapon.CubeBlock.DisplayNameText);
                                break;
                            }
                        }
                        else
                        {
                            Log.DebugLog("no ammo: " + weapon.CubeBlock.DisplayNameText);
                        }
                    }
                    else
                    {
                        Log.DebugLog("not working: " + weapon.CubeBlock.DisplayNameText);
                        m_weapons_all.Remove(weapon);
                        removed = true;
                    }
                }
            }

            if (removed)
            {
                m_weapons_fixed.ApplyRemovals();
                m_weapons_all.ApplyRemovals();
                m_weaponDataDirty = true;
            }

            if (weapon_primary == null)
            {
                m_weapon_primary        = null;
                m_weapon_primary_pseudo = null;
                return;
            }

            if (m_weapon_primary != weapon_primary)
            {
                m_weapon_primary = weapon_primary;
                IMyCubeBlock faceBlock;
                FixedWeapon  fixedWeapon = weapon_primary as FixedWeapon;
                if (fixedWeapon != null && fixedWeapon.CubeBlock.CubeGrid != m_controlBlock.CubeGrid)
                {
                    faceBlock = fixedWeapon.MotorTurretFaceBlock();
                    Log.DebugLog("MotorTurretFaceBlock == null", Logger.severity.FATAL, condition: faceBlock == null);
                }
                else
                {
                    faceBlock = weapon_primary.CubeBlock;
                }

                if (m_mover.SignificantGravity())
                {
                    if (m_mover.Thrust.Standard.LocalMatrix.Forward == faceBlock.LocalMatrix.Forward)
                    {
                        Log.DebugLog("primary forward matches Standard forward");
                        Matrix localMatrix = m_mover.Thrust.Standard.LocalMatrix;
                        localMatrix.Translation = faceBlock.LocalMatrix.Translation;
                        m_weapon_primary_pseudo = new PseudoBlock(() => faceBlock.CubeGrid, localMatrix);
                        return;
                    }
                    if (m_mover.Thrust.Gravity.LocalMatrix.Forward == faceBlock.LocalMatrix.Forward)
                    {
                        Log.DebugLog("primary forward matches Gravity forward");
                        Matrix localMatrix = m_mover.Thrust.Gravity.LocalMatrix;
                        localMatrix.Translation = faceBlock.LocalMatrix.Translation;
                        m_weapon_primary_pseudo = new PseudoBlock(() => faceBlock.CubeGrid, localMatrix);
                        return;
                    }
                    Log.DebugLog("cannot match primary forward to a standard flight matrix. primary forward: " + faceBlock.LocalMatrix.Forward +
                                 ", Standard forward: " + m_mover.Thrust.Standard.LocalMatrix.Forward + ", gravity forward: " + m_mover.Thrust.Gravity.LocalMatrix.Forward);
                }
                m_weapon_primary_pseudo = new PseudoBlock(faceBlock);
            }
        }