Beispiel #1
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)
                        {
                            m_logger.debugLog("has target: " + weapon.CubeBlock.DisplayNameText);
                            break;
                        }
                    }
                    else
                        m_logger.debugLog("no ammo: " + weapon.CubeBlock.DisplayNameText);
                }
                else
                {
                    m_logger.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)
                            {
                                m_logger.debugLog("has target: " + weapon.CubeBlock.DisplayNameText);
                                break;
                            }
                        }
                        else
                            m_logger.debugLog("no ammo: " + weapon.CubeBlock.DisplayNameText);
                    }
                    else
                    {
                        m_logger.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;
                if (m_mover.SignificantGravity())
                {
                    if (m_mover.Thrust.Standard.LocalMatrix.Forward == weapon_primary.CubeBlock.LocalMatrix.Forward)
                    {
                        m_logger.debugLog("primary forward matches Standard forward");
                        Matrix localMatrix = m_mover.Thrust.Standard.LocalMatrix;
                        localMatrix.Translation = weapon_primary.CubeBlock.LocalMatrix.Translation;
                        m_weapon_primary_pseudo = new PseudoBlock(() => weapon_primary.CubeBlock.CubeGrid, localMatrix);
                        return;
                    }
                    if (m_mover.Thrust.Gravity.LocalMatrix.Forward == weapon_primary.CubeBlock.LocalMatrix.Forward)
                    {
                        m_logger.debugLog("primary forward matches Gravity forward");
                        Matrix localMatrix = m_mover.Thrust.Gravity.LocalMatrix;
                        localMatrix.Translation = weapon_primary.CubeBlock.LocalMatrix.Translation;
                        m_weapon_primary_pseudo = new PseudoBlock(() => weapon_primary.CubeBlock.CubeGrid, localMatrix);
                        return;
                    }
                    m_logger.debugLog("cannot match primary forward to a standard flight matrix. primary forward: " + weapon_primary.CubeBlock.LocalMatrix.Forward +
                        ", Standard forward: " + m_mover.Thrust.Standard.LocalMatrix.Forward + ", gravity forward: " + m_mover.Thrust.Gravity.LocalMatrix.Forward);
                }
                m_weapon_primary_pseudo = new PseudoBlock(weapon_primary.CubeBlock);
            }
        }
Beispiel #2
0
		private void GetPrimaryWeapon()
		{
			if (m_weapon_primary != null && m_weapon_primary.CubeBlock.IsWorking && m_weapon_primary.CurrentTarget.Entity != null)
				return;

			m_weapon_primary = null;
			m_weapon_primary_pseudo = null;

			bool removed = false;
			foreach (FixedWeapon weapon in m_weapons_fixed)
				if (weapon.CubeBlock.IsWorking)
				{
					m_weapon_primary = weapon;
					if (weapon.CurrentTarget.Entity != null)
						break;
				}
				else
				{
					m_weapons_fixed.Remove(weapon);
					weapon.EngagerReleaseControl();
					removed = true;
				}

			if (m_weapon_primary == null)
				foreach (WeaponTargeting weapon in m_weapons_all)
					if (weapon.CubeBlock.IsWorking)
					{
						m_weapon_primary = weapon;
						if (weapon.CurrentTarget.Entity != null)
							break;
					}
					else
					{
						m_weapons_all.Remove(weapon);
						removed = true;
					}

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

			if (m_weapon_primary != null)
				m_weapon_primary_pseudo = new PseudoBlock(m_weapon_primary.CubeBlock);
		}