示例#1
0
        /// <summary>
        /// Fire weapons at selected targets.
        /// </summary>
        /// <param name="battlingStacks">All stacks in the battle.</param>
        private List <WeaponDetails> GenerateAttacks(List <Stack> battlingStacks)
        {
            // First, identify all of the weapons and their characteristics for
            // every ship stack present at the battle and who they are pointed at.

            List <WeaponDetails> allAttacks = new List <WeaponDetails>();

            foreach (Stack stack in battlingStacks)
            {
                if (!stack.IsDestroyed)
                {
                    // generate an attack for each weapon slot in the Design (all ships in the Token fire weapons in the same slot at the same time)
                    foreach (Weapon weaponSystem in stack.Token.Design.Weapons)
                    {
                        WeaponDetails weapon = new WeaponDetails();

                        weapon.SourceStack = stack;
                        weapon.TargetStack = stack.Target;
                        weapon.Weapon      = weaponSystem;

                        allAttacks.Add(weapon);
                    }
                }
            }

            // Sort the weapon list according to weapon system initiative.
            allAttacks.Sort();

            return(allAttacks);
        }
示例#2
0
        /// <summary>
        /// Attempt an attack.
        /// </summary>
        /// <param name="allAttacks">A list of WeaponDetails representing a round of attacks.</param>
        private bool ProcessAttack(WeaponDetails attack)
        {
            // First, check that the target stack we originally identified has not
            // been destroyed (actually, the stack still exists at this point but
            // it may have no ship tokens left). In which case, don't bother trying to
            // fire this weapon system (we'll wait until the next battle clock
            // "tick" and re-target then).
            if (attack.TargetStack == null || attack.TargetStack.IsDestroyed)
            {
                return(false);
            }

            if (attack.SourceStack == null || attack.SourceStack.IsDestroyed)
            {
                // Report.Error("attacking stack no longer exists");
                return(false);
            }

            // If the target stack is not within the range of this weapon system
            // then there is no point in trying to fire it.
            if (PointUtilities.Distance(attack.SourceStack.Position, attack.TargetStack.Position) > attack.Weapon.Range)
            {
                return(false);
            }

            // Target is valid; execute attack.
            ExecuteAttack(attack);

            return(true);
        }
示例#3
0
        /// <summary>
        /// DischargeWeapon. We know the weapon and we know the target stack so attack.
        /// </summary>
        /// <param name="ship">The firing stack.</param>
        /// <param name="details">The weapon being fired.</param>
        /// <param name="target">The target stack.</param>
        private void ExecuteAttack(WeaponDetails attack)
        {
            // the two stacks involved in the attack
            Stack attacker = attack.SourceStack;
            Stack target   = attack.TargetStack;

            // Report on the targeting.
            BattleStepTarget report = new BattleStepTarget();

            report.StackKey  = attack.SourceStack.Key;
            report.TargetKey = attack.TargetStack.Key;
            battle.Steps.Add(report);

            // Identify the attack parameters that have to take into account
            // factors other than the base values (e.g. jammers, capacitors, etc.)
            double hitPower = CalculateWeaponPower(attacker.Token.Design, attack.Weapon, target.Token.Design);
            double accuracy = CalculateWeaponAccuracy(attacker.Token.Design, attack.Weapon, target.Token.Design);

            if (attack.Weapon.IsMissile)
            {
                FireMissile(attacker, target, hitPower, accuracy);
            }
            else
            {
                FireBeam(attacker, target, hitPower);
            }

            // If we still have some Armor then the stack hasn't been destroyed
            // yet so this is the end of this shot.

            // FIXME (Priority 7) What about losses of a single ship within the token???
            if (target.Token.Armor <= 0)
            {
                DestroyStack(attacker, target);
            }
        }
示例#4
0
        public int CompareTo(object rightHandSide)
        {
            WeaponDetails rhs = (WeaponDetails)rightHandSide;

            return(this.Weapon.Initiative.CompareTo(rhs.Weapon.Initiative));
        }