Exemple #1
0
 public override bool BeBumped(Ship source)
 {
     if (source is PlayerShip)
     {
         if (IsExplored)
         {
             if (Colony == null)
             {
                 if (mineralValue > 0)
                 {
                     Log.Add("A landing team has collected $" + mineralValue + " worth of useful materials!", Color.Gold);
                     PlayerShip.Instance.Savings += mineralValue;
                     mineralValue = 0;
                     Color        = Color.Gray;
                 }
                 else
                 {
                     Log.Add("This planet is uninhabited; there's nothing of interest here.");
                 }
             }
             else if (StarSystem.FindSpaceObjects <EnemyShip>().Any() || StarSystem.FindSpaceObjects <EnemyShipyard>().Any())
             {
                 Log.Add("The colony hails you: \"Take care of the Jraenar invaders in the system first!\"", Color.Yellow);
             }
             else
             {
                 Log.Add("The colony repairs your ship and opens up its spacedock.");
                 foreach (var comp in PlayerShip.Instance.Components)
                 {
                     comp.Hitpoints = comp.MaxHitpoints;
                 }
                 new ShopForm(Colony).ShowDialog();
                 PlayerShip.Instance.Shields = PlayerShip.Instance.MaxShields; // do this after shopping in case the player bought a shield
             }
         }
         else
         {
             // explore the planet
             Explore(true);
         }
     }
     return(true);
 }
Exemple #2
0
        public override bool Move()
        {
            if (PlayerShip.Instance.StarSystem == StarSystem)
            {
                // player ship sighted!
                NeedsNewWaypoint = false;
                int desiredRange;
                var ourRanges   = Components.Select(c => c.WeaponInfo).Where(w => w != null).Select(w => w.Range).Distinct();
                var theirRanges = PlayerShip.Instance.Components.Select(c => c.WeaponInfo).Where(w => w != null).Select(w => w.Range).Distinct();
                if (!ourRanges.Any())
                {
                    // RUN AWAY!!!
                    // get new waypoint - random warp point to "patrol"
                    desiredRange     = int.MaxValue;
                    NeedsNewWaypoint = false;
                    var wp = StarSystem.FindSpaceObjects <WarpPoint>().PickRandom();
                    WaypointX = wp.X;
                    WaypointY = wp.Y;
                }
                else if (ourRanges.Any(r => r > theirRanges.Max()))
                {
                    // stay at max range of closest ranged weapon that is outside their max range
                    desiredRange = ourRanges.Where(r => r > theirRanges.Max()).Min();
                }
                else
                {
                    // stay at max range of closest ranged weapon
                    desiredRange = ourRanges.Min();
                }
                if (desiredRange < int.MaxValue)
                {
                    // stay at desired range
                    var dir = Utilities.Pathfind(StarSystem, X, Y, (nx, ny) =>
                    {
                        var dist   = Math.Abs(Utilities.Distance(nx, ny, PlayerShip.Instance.X, PlayerShip.Instance.Y));
                        var offset = dist - desiredRange;

                        // being too close is better than being too far away
                        if (offset > 0)
                        {
                            return(offset * 2);
                        }
                        else
                        {
                            return(-offset);
                        }
                    });
                    Go(dir);
                    return(true);
                }
            }
            else if (NeedsNewWaypoint)
            {
                // get new waypoint - random warp point to "patrol"
                NeedsNewWaypoint = false;
                var wp = StarSystem.FindSpaceObjects <WarpPoint>().PickRandom();
                WaypointX = wp.X;
                WaypointY = wp.Y;
            }
            else
            {
                // continue toward old waypoint, nothing to do here
            }

            // pursue warp point
            var wpDir = Utilities.Pathfind(StarSystem, X, Y, (nx, ny) => Utilities.Distance(nx, ny, WaypointX, WaypointY));

            Go(wpDir);

            // no need to wait for player input
            return(true);
        }