Esempio n. 1
0
        public override void Attack()
        {
            var fired = new List <Component>();

            // first targeting priority: shipyards
            // find weapons to fire
            bool didstuff = false;

            do
            {
                didstuff = false;
                foreach (var comp in Components.Where(c => c.WeaponInfo != null && c.WeaponInfo.Wait <= 0))
                {
                    var sys = FindSpaceObjectsInRange <EnemyShipyard>(comp.WeaponInfo.Range).Where(sy => sy.IsRevealed);
                    if (sys.Any())
                    {
                        // find closest
                        EnemyShipyard target = null;
                        var           dist   = int.MaxValue;
                        foreach (var sy in sys)
                        {
                            var nd = Utilities.Distance(X, Y, sy.X, sy.Y);
                            if (nd < dist)
                            {
                                target = sy;
                                dist   = nd;
                            }
                        }

                        // fire!
                        Log.Add("Firing " + comp + " at the Jraenar shipyard!");
                        fired.Add(comp);
                        target.TakeDamage(comp.WeaponInfo.Damage);
                        comp.WeaponInfo.Wait += comp.WeaponInfo.ReloadRate;
                        didstuff              = true;
                    }
                }
            } while (didstuff);

            // second targeting priority: enemy ships
            // find weapons to fire
            do
            {
                didstuff = false;
                foreach (var comp in Components.Where(c => c.WeaponInfo != null && !fired.Contains(c) && c.WeaponInfo.Wait <= 0))
                {
                    var ships = FindSpaceObjectsInRange <EnemyShip>(comp.WeaponInfo.Range);
                    if (ships.Any())
                    {
                        // find closest
                        EnemyShip target = null;
                        var       dist   = int.MaxValue;
                        foreach (var sy in ships)
                        {
                            var nd = Utilities.Distance(X, Y, sy.X, sy.Y);
                            if (nd < dist)
                            {
                                target = sy;
                                dist   = nd;
                            }
                        }

                        // fire!
                        Log.Add("Firing " + comp + " at the " + target + "!");
                        if (target.RollEvasionOrPD(comp.WeaponInfo.IsMissile))
                        {
                            if (comp.WeaponInfo.IsMissile)
                            {
                                Log.Add("It was shot down!", Color.Yellow);
                            }
                            else
                            {
                                Log.Add("We missed!", Color.Yellow);
                            }
                        }
                        else
                        {
                            target.TakeDamage(comp.WeaponInfo.Damage);
                        }
                        comp.WeaponInfo.Wait += comp.WeaponInfo.ReloadRate;
                        didstuff              = true;
                    }
                }
            } while (didstuff);
        }
Esempio n. 2
0
 public bool CanSee(EnemyShipyard sy)
 {
     return(sy.IsRevealed || StarSystem == sy.StarSystem && Utilities.Distance(X, Y, sy.Y, sy.Y) <= SensorRange);
 }