/// <summary>Obtain details of a ship given its model</summary>
        public static Ship FromModel(string model)
        {
            if (model == null)
            {
                return null;
            }

            Ship Ship = new Ship();
            Ship Template;
            if (ShipsByModel.TryGetValue(model.ToLowerInvariant(), out Template))
            {
                Ship.EDID = Template.EDID;
                Ship.EDName = Template.EDName;
                Ship.manufacturer = Template.manufacturer;
                Ship.phoneticmanufacturer = Template.phoneticmanufacturer;
                Ship.model = Template.model;
                Ship.phoneticmodel = Template.phoneticmodel;
                Ship.size = Template.size;
            }
            else
            {
                Ship.model = model;
            }
            return Ship;
        }
 public ShipSoldEvent(DateTime timestamp, Ship ship, long price) : base(timestamp, NAME)
 {
     this.Ship = ship;
     this.ship = (ship == null ? null : ship.model);
     this.shipid = (ship == null ? (int?)null : ship.LocalId);
     this.price = price;
 }
 public ShipTransferInitiatedEvent(DateTime timestamp, Ship ship, string system, decimal distance, long price) : base(timestamp, NAME)
 {
     this.ship = (ship == null ? null : ship.model);
     this.shipid = (ship == null ? (int?)null : ship.LocalId);
     this.system = system;
     this.distance = distance;
     this.price = price;
 }
        public void Say(Ship ship, string speech, bool wait, int priority = 3)
        {
            if (speech == null)
            {
                return;
            }

            Speak(speech, null, echoDelayForShip(ship), distortionLevelForShip(ship), chorusLevelForShip(ship), reverbLevelForShip(ship), 0, wait, priority);
        }
 public CommanderContinuedEvent(DateTime timestamp, string commander, Ship ship, GameMode mode, string group, decimal credits) : base(timestamp, NAME)
 {
     this.commander = commander;
     this.Ship = ship;
     this.ship = (ship == null ? null : ship.model);
     this.shipid = (ship == null ? (int?)null : ship.LocalId);
     this.mode = (mode == null ? null : mode.name);
     this.group = group;
     this.credits = credits;
 }
 public ShipPurchasedEvent(DateTime timestamp, Ship ship, long price, Ship soldShip, long? soldPrice, Ship storedShip) : base(timestamp, NAME)
 {
     this.Ship = ship;
     this.ship = (ship == null ? null : ship.model);
     this.price = price;
     this.soldship = (soldShip == null ? null : soldShip.model);
     this.soldname = (soldShip == null ? null : soldShip.name);
     this.soldprice = soldPrice;
     this.storedship = (storedShip == null ? null : storedShip.model);
     this.storedname = (storedShip == null ? null : storedShip.name);
 }
 public ShipSwappedEvent(DateTime timestamp, Ship ship, Ship soldship, Ship storedship) : base(timestamp, NAME)
 {
     this.Ship = ship;
     this.ship = (ship == null ? null : ship.model);
     this.shipid = (ship == null ? (int?)null : ship.LocalId);
     this.SoldShip = SoldShip;
     this.soldship = (soldship == null ? null : soldship.model);
     this.soldshipid = (soldship == null ? (int?)null : soldship.LocalId);
     this.StoredShip = StoredShip;
     this.storedship = (storedship == null ? null : storedship.model);
     this.storedshipid = (storedship == null ? (int?)null : storedship.LocalId);
 }
        /// <summary>Obtain details of a ship given its Elite ID</summary>
        public static Ship FromEliteID(long id)
        {
            Ship Ship = new Ship();
            Ship Template;
            if (ShipsByEliteID.TryGetValue(id, out Template))
            {
                Ship.EDID = Template.EDID;
                Ship.EDName = Template.EDName;
                Ship.manufacturer = Template.manufacturer;
                Ship.phoneticmanufacturer = Template.phoneticmanufacturer;
                Ship.model = Template.model;
                Ship.phoneticmodel = Template.phoneticmodel;
                Ship.size = Template.size;
            }
            // All ships default to 100% health
            Ship.health = 100;

            return Ship;
        }
        private EDDI()
        {
            try
            {
                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " starting");

                // Start by ensuring that our primary data structures have something in them.  This allows them to be updated
                // from any source
                Cmdr = new Commander();
                Ship = new Ship();
                Shipyard = new List<Ship>();

                // Set up the EDDI configuration
                EDDIConfiguration configuration = EDDIConfiguration.FromFile();
                Logging.Verbose = configuration.Debug;
                if (configuration.HomeSystem != null && configuration.HomeSystem.Trim().Length > 0)
                {
                    HomeStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(configuration.HomeSystem.Trim());
                    if (HomeStarSystem != null)
                    {
                        Logging.Debug("Home star system is " + HomeStarSystem.name);
                        if (configuration.HomeStation != null && configuration.HomeStation.Trim().Length > 0)
                        {
                            string homeStationName = configuration.HomeStation.Trim();
                            foreach (Station station in HomeStarSystem.stations)
                            {
                                if (station.name == homeStationName)
                                {
                                    HomeStation = station;
                                    Logging.Debug("Home station is " + HomeStation.name);
                                    break;

                                }
                            }
                        }
                    }
                }

                // Set up the app service
                if (CompanionAppService.Instance.CurrentState == CompanionAppService.State.READY)
                {
                    // Carry out initial population of profile
                    try
                    {
                        refreshProfile();
                    }
                    catch (Exception ex)
                    {
                        Logging.Debug("Failed to obtain profile: " + ex);
                    }
                }

                Cmdr.insurance = configuration.Insurance;
                if (Cmdr.name != null)
                {
                    Logging.Info("EDDI access to the companion app is enabled");
                }
                else
                {
                    // If InvokeUpdatePlugin failed then it will have have left an error message, but this once we ignore it
                    Logging.Info("EDDI access to the companion app is disabled");
                }

                // Set up the star map service
                StarMapConfiguration starMapCredentials = StarMapConfiguration.FromFile();
                if (starMapCredentials != null && starMapCredentials.apiKey != null)
                {
                    // Commander name might come from star map credentials or the companion app's profile
                    string commanderName = null;
                    if (starMapCredentials.commanderName != null)
                    {
                        commanderName = starMapCredentials.commanderName;
                    }
                    else if (Cmdr != null && Cmdr.name != null)
                    {
                        commanderName = Cmdr.name;
                    }
                    if (commanderName != null)
                    {
                        starMapService = new StarMapService(starMapCredentials.apiKey, commanderName);
                        Logging.Info("EDDI access to EDSM is enabled");
                    }
                }
                if (starMapService == null)
                {
                    Logging.Info("EDDI access to EDSM is disabled");
                }

                // We always start in normal space
                Environment = Constants.ENVIRONMENT_NORMAL_SPACE;

                // Set up monitors and responders
                monitors = findMonitors();
                responders = findResponders();

                // Check for an update
                string response;
                try
                {
                    if (Constants.EDDI_VERSION.Contains("b"))
                    {
                        response = Net.DownloadString("http://api.eddp.co/betaversion");
                    }
                    else
                    {
                        response = Net.DownloadString("http://api.eddp.co/version");
                    }
                    if (Versioning.Compare(response, Constants.EDDI_VERSION) == 1)
                    {
                        SpeechService.Instance.Say(null, "EDDI version " + response.Replace(".", " point ") + " is now available.", false);
                    }
                }
                catch
                {
                    SpeechService.Instance.Say(null, "There was a problem connecting to external data services; some features may not work fully", false);
                }

                Logging.Info(Constants.EDDI_NAME + " " + Constants.EDDI_VERSION + " initialised");
            }
            catch (Exception ex)
            {
                Logging.Error("Failed to initialise", ex);
            }
        }
 private void SetShip(Ship ship)
 {
     if (ship == null)
     {
         Logging.Warn("Refusing to set ship to null");
     }
     else
     {
         Logging.Debug("Set ship to " + JsonConvert.SerializeObject(ship));
         Ship = ship;
     }
 }
 public ShipDeliveredEvent(DateTime timestamp, Ship ship) : base(timestamp, NAME)
 {
     this.Ship = ship;
     this.ship = (ship == null ? null : ship.model);
     this.shipid = (ship == null ? (int?)null : ship.LocalId);
 }
        public static string ShipUri(Ship ship)
        {
            int modsSize = 0;
            string enableds = "";
            string priorities = "";

            string uri = "https://coriolis.edcd.io/outfit/";

            using (MemoryStream stream = new MemoryStream())
            {
                using (var compressionStream = new GZipStream(stream, CompressionLevel.Optimal, true))
                using (BinaryWriter writer = new BinaryWriter(compressionStream))
                {
                    uri += shipModels[ship.model];
                    uri += "/";

                    byte position = 0;
                    uri += ShipBulkheads(ship.bulkheads.name);
                    modsSize += addModifications(ship.bulkheads, position++, writer);
                    enableds += "1";
                    priorities += "4";
                    uri += CoriolisIDDefinitions.FromEDDBID(ship.powerplant.EDDBID);
                    modsSize += addModifications(ship.powerplant, position++, writer);
                    enableds += "1";
                    priorities += "0";
                    uri += CoriolisIDDefinitions.FromEDDBID(ship.thrusters.EDDBID);
                    modsSize += addModifications(ship.thrusters, position++, writer);
                    enableds += ship.thrusters.enabled ? "1" : "0";
                    priorities += ship.thrusters.priority;
                    uri += CoriolisIDDefinitions.FromEDDBID(ship.frameshiftdrive.EDDBID);
                    modsSize += addModifications(ship.frameshiftdrive, position++, writer);
                    enableds += ship.frameshiftdrive.enabled ? "1" : "0";
                    priorities += ship.frameshiftdrive.priority;
                    uri += CoriolisIDDefinitions.FromEDDBID(ship.lifesupport.EDDBID);
                    modsSize += addModifications(ship.lifesupport, position++, writer);
                    enableds += ship.lifesupport.enabled ? "1" : "0";
                    priorities += ship.lifesupport.priority;
                    uri += CoriolisIDDefinitions.FromEDDBID(ship.powerdistributor.EDDBID);
                    modsSize += addModifications(ship.powerdistributor, position++, writer);
                    enableds += ship.powerdistributor.enabled ? "1" : "0";
                    priorities += ship.powerdistributor.priority;
                    uri += CoriolisIDDefinitions.FromEDDBID(ship.sensors.EDDBID);
                    modsSize += addModifications(ship.sensors, position++, writer);
                    enableds += ship.sensors.enabled ? "1" : "0";
                    priorities += ship.sensors.priority;
                    uri += CoriolisIDDefinitions.FromEDDBID(ship.fueltank.EDDBID);
                    modsSize += addModifications(ship.fueltank, position++, writer);
                    enableds += "1";
                    priorities += "1";
                    foreach (Hardpoint Hardpoint in ship.hardpoints)
                    {
                        if (Hardpoint.module == null)
                        {
                            uri += "-";
                            enableds += "1";
                            priorities += "0";
                        }
                        else
                        {
                            string id = CoriolisIDDefinitions.FromEDDBID(Hardpoint.module.EDDBID);
                            if (id == null)
                            {
                                uri += "-";
                                enableds += "1";
                                priorities += "0";
                            }
                            else
                            {
                                uri += id;
                                enableds += Hardpoint.module.enabled ? "1" : "0";
                                priorities += Hardpoint.module.priority;
                                modsSize += addModifications(Hardpoint.module, position, writer);
                            }
                        }
                        position++;
                    }
                    foreach (Compartment Compartment in ship.compartments)
                    {
                        if (Compartment.module == null)
                        {
                            uri += "-";
                            enableds += "1";
                            priorities += "0";
                        }
                        else
                        {
                            string id = CoriolisIDDefinitions.FromEDDBID(Compartment.module.EDDBID);
                            if (id == null)
                            {
                                uri += "-";
                                enableds += "1";
                                priorities += "0";
                            }
                            else
                            {
                                uri += id;
                                enableds += Compartment.module.enabled ? "1" : "0";
                                priorities += Compartment.module.priority;
                                modsSize += addModifications(Compartment.module, position, writer);
                            }
                        }
                        position++;
                    }

                    writer.Write((byte)0xff);
                    modsSize++;

                    uri += ".";
                    uri += LZString.compressToBase64(enableds).Replace('/', '-');
                    uri += ".";
                    uri += LZString.compressToBase64(priorities).Replace('/', '-');
                    uri += ".";

                }
                uri += Convert.ToBase64String(stream.ToArray()).Replace('/', '-');
                Logging.Debug("Sizes are " + modsSize + "/" + stream.Length + "/" + Convert.ToBase64String(stream.ToArray()).Length);

                string bn;
                if (ship.name == null)
                {
                    bn = ship.role + " " + ship.model;
                }
                else
                {
                    bn = ship.name;
                }
                uri += "?bn=" + Uri.EscapeDataString(bn);

                return uri;
            }
        }
 /// <summary>Obtain details of a ship given its Elite:Dangerous model</summary>
 public static Ship FromEDModel(string model)
 {
     if (model == null)
     {
         return null;
     }
     Ship Ship = new Ship();
     Ship Template;
     if (ShipsByEDModel.TryGetValue(model.ToLowerInvariant().Replace(" ", "").Replace(".", "").Replace("_", ""), out Template))
     {
         Ship.EDID = Template.EDID;
         Ship.EDName = Template.EDName;
         Ship.manufacturer = Template.manufacturer;
         Ship.phoneticmanufacturer = Template.phoneticmanufacturer;
         Ship.model = Template.model;
         Ship.phoneticmodel = Template.phoneticmodel;
         Ship.size = Template.size;
     }
     else
     {
         Logging.Info("Failed to find ship");
         Ship.model = model;
     }
     return Ship;
 }
 private int echoDelayForShip(Ship ship)
 {
     // this is affected by ship size
     int echoDelay = 50; // Default
     if (ship != null)
     {
         if (ship.size == "Small")
         {
             echoDelay = 50;
         }
         else if (ship.size == "Medium")
         {
             echoDelay = 100;
         }
         else if (ship.size == "Large")
         {
             echoDelay = 200;
         }
         else if (ship.size == "Huge")
         {
             echoDelay = 400;
         }
     }
     return echoDelay;
 }
        private static void AugmentShipInfo(Ship ship, List<Ship> storedShips)
        {
            Logging.Debug("Entered");
            ShipsConfiguration shipsConfiguration = ShipsConfiguration.FromFile();
            Dictionary<int, Ship> lookup = shipsConfiguration.Ships.ToDictionary(o => o.LocalId);

            Ship shipConfig;
            // Start with our current ship
            if (lookup.TryGetValue(ship.LocalId, out shipConfig))
            {
                // Already exists; grab the relevant information and supplement it
                // Ship config name might be just whitespace, in which case we unset it
                if (shipConfig.name != null && shipConfig.name.Trim().Length > 0)
                {
                    ship.name = shipConfig.name.Trim();
                }
                if (shipConfig.phoneticname != null && shipConfig.phoneticname.Trim().Length > 0)
                {
                    ship.phoneticname = shipConfig.phoneticname.Trim();
                }
                ship.role = shipConfig.role;
            }
            else
            {
                // Doesn't already exist; add a default role
                ship.role = Role.MultiPurpose;
            }

            // Work through our shipyard
            foreach (Ship storedShip in storedShips)
            {
                if (lookup.TryGetValue(storedShip.LocalId, out shipConfig))
                {
                    // Already exists; grab the relevant information and supplement it
                    storedShip.name = shipConfig.name;
                    storedShip.phoneticname = shipConfig.phoneticname;
                    storedShip.role = shipConfig.role;
                }
                else
                {
                    // Doesn't already exist; add a default role
                    storedShip.role = Role.MultiPurpose;
                }
            }

            // Update our configuration with the new data (this also removes any old redundant ships)
            shipsConfiguration.Ships = new List<Ship>();
            shipsConfiguration.Ships.Add(ship);
            shipsConfiguration.Ships.AddRange(storedShips);
            shipsConfiguration.ToFile();
            Logging.Debug("Leaving");
        }
        private static void setShipValues(Ship ship, string prefix, ref dynamic vaProxy)
        {
            Logging.Debug("Setting ship information (" + prefix + ")");
            try
            {
                vaProxy.SetText(prefix + " manufacturer", ship == null ? null : ship.manufacturer);
                vaProxy.SetText(prefix + " model", ship == null ? null : ship.model);
                vaProxy.SetText(prefix + " model (spoken)", ship == null ? null : ship.SpokenModel());

                if (EDDI.Instance.Ship != null && EDDI.Instance.Cmdr != null && EDDI.Instance.Cmdr.name != null)
                {
                    vaProxy.SetText(prefix + " callsign", ship == null ? null : ship.manufacturer + " " + EDDI.Instance.Cmdr.name.Substring(0, 3).ToUpperInvariant());
                    vaProxy.SetText(prefix + " callsign (spoken)", ship == null ? null : ship.SpokenManufacturer() + " " + Translations.CallSign(EDDI.Instance.Cmdr.name.Substring(0, 3).ToUpperInvariant()));
                }

                vaProxy.SetText(prefix + " name", ship == null ? null : ship.name);
                vaProxy.SetText(prefix + " role", ship == null || ship.role == null ? null : ship.role.ToString());
                vaProxy.SetText(prefix + " size", ship == null || ship.size == null ? null : ship.size.ToString());
                vaProxy.SetDecimal(prefix + " value", ship == null ? (decimal?)null : ship.value);
                vaProxy.SetText(prefix + " value (spoken)", ship == null ? null : Translations.Humanize(ship.value));
                vaProxy.SetDecimal(prefix + " health", ship == null ? (decimal?)null : ship.health);
                vaProxy.SetInt(prefix + " cargo capacity", ship == null ? (int?)null : ship.cargocapacity);
                vaProxy.SetInt(prefix + " cargo carried", ship == null ? (int?)null : ship.cargocarried);
                // Add number of limpets carried
                if (ship == null || ship.cargo == null)
                {
                    vaProxy.SetInt(prefix + " limpets carried", null);
                }
                else
                {
                    int limpets = 0;
                    foreach (Cargo cargo in ship.cargo)
                    {
                        if (cargo.commodity.name == "Limpet")
                        {
                            limpets += cargo.amount;
                        }
                    }
                    vaProxy.SetInt(prefix + " limpets carried", limpets);
                }

                setShipModuleValues(ship == null ? null : ship.bulkheads, prefix + " bulkheads", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.bulkheads, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " bulkheads", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.powerplant, prefix + " power plant", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.powerplant, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " power plant", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.thrusters, prefix + " thrusters", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.thrusters, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " thrusters", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.frameshiftdrive, prefix + " frame shift drive", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.frameshiftdrive, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " frame shift drive", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.lifesupport, prefix + " life support", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.lifesupport, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " life support", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.powerdistributor, prefix + " power distributor", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.powerdistributor, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " power distributor", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.sensors, prefix + " sensors", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.sensors, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " sensors", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.fueltank, prefix + " fuel tank", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.fueltank, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, prefix + " fuel tank", ref vaProxy);

                // Special for fuel tank - capacity and total capacity
                vaProxy.SetDecimal(prefix + " fuel tank capacity",  ship == null ? (decimal?)null : ship.fueltankcapacity);
                vaProxy.SetDecimal(prefix + " total fuel tank capacity", ship == null ? (decimal?)null : ship.fueltanktotalcapacity);

                // Hardpoints
                if (ship != null)
                {
                    int numTinyHardpoints = 0;
                    int numSmallHardpoints = 0;
                    int numMediumHardpoints = 0;
                    int numLargeHardpoints = 0;
                    int numHugeHardpoints = 0;
                    foreach (Hardpoint Hardpoint in ship.hardpoints)
                    {
                        string baseHardpointName = prefix;
                        switch (Hardpoint.size)
                        {
                            case 0:
                                baseHardpointName = prefix + " tiny hardpoint " + ++numTinyHardpoints;
                                break;
                            case 1:
                                baseHardpointName = prefix + " small hardpoint " + ++numSmallHardpoints;
                                break;
                            case 2:
                                baseHardpointName = prefix + " medium hardpoint " + ++numMediumHardpoints;
                                break;
                            case 3:
                                baseHardpointName = prefix + " large hardpoint " + ++numLargeHardpoints;
                                break;
                            case 4:
                                baseHardpointName = prefix + " huge hardpoint " + ++numHugeHardpoints;
                                break;
                        }

                        vaProxy.SetBoolean(baseHardpointName + " occupied", Hardpoint.module != null);
                        setShipModuleValues(Hardpoint.module, baseHardpointName + " module", ref vaProxy);
                        setShipModuleOutfittingValues(ship == null ? null : Hardpoint.module, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, baseHardpointName + " module", ref vaProxy);
                    }

                    vaProxy.SetInt(prefix + " hardpoints", numSmallHardpoints + numMediumHardpoints + numLargeHardpoints + numHugeHardpoints);
                    vaProxy.SetInt(prefix + " utility slots", numTinyHardpoints);
                    // Compartments
                    int curCompartment = 0;
                    foreach (Compartment Compartment in ship.compartments)
                    {
                        string baseCompartmentName = prefix + " compartment " + ++curCompartment;
                        vaProxy.SetInt(baseCompartmentName + " size", Compartment.size);
                        vaProxy.SetBoolean(baseCompartmentName + " occupied", Compartment.module != null);
                        setShipModuleValues(Compartment.module, baseCompartmentName + " module", ref vaProxy);
                        setShipModuleOutfittingValues(ship == null ? null : Compartment.module, EDDI.Instance.CurrentStation == null ? null : EDDI.Instance.CurrentStation.outfitting, baseCompartmentName + " module", ref vaProxy);
                    }
                    vaProxy.SetInt(prefix + " compartments", curCompartment);
                }

                // Fetch the star system in which the ship is stored
                if (ship != null && ship.starsystem != null)
                {
                    vaProxy.SetText(prefix + " system", ship.starsystem);
                    vaProxy.SetText(prefix + " station", ship.station);
                    StarSystem StoredShipStarSystem = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(ship.starsystem);
                    // Have to grab a local copy of our star system as CurrentStarSystem might not have been initialised yet
                    StarSystem ThisStarSystem = StarSystemSqLiteRepository.Instance.GetStarSystem(EDDI.Instance.CurrentStarSystem.name);

                    // Work out the distance to the system where the ship is stored if we can
                    if (ThisStarSystem != null && ThisStarSystem.x != null && StoredShipStarSystem.x != null)
                    {
                        decimal distance = (decimal)Math.Round(Math.Sqrt(Math.Pow((double)(ThisStarSystem.x - StoredShipStarSystem.x), 2)
                            + Math.Pow((double)(ThisStarSystem.y - StoredShipStarSystem.y), 2)
                            + Math.Pow((double)(ThisStarSystem.z - StoredShipStarSystem.z), 2)), 2);
                        vaProxy.SetDecimal(prefix + " distance", distance);
                    }
                    else
                    {
                        // We don't know how far away the ship is
                        vaProxy.SetDecimal(prefix + " distance", null);
                    }
                }

                setStatus(ref vaProxy, "Operational");
            }
            catch (Exception e)
            {
                setStatus(ref vaProxy, "Failed to set ship information", e);
            }

            Logging.Debug("Set ship information");
        }
        private int distortionLevelForShip(Ship ship)
        {
            // This is affected by ship health
            int distortionLevel = 0;
            if (ship != null && configuration.DistortOnDamage)
            {

                distortionLevel = Math.Min((100 - (int)ship.health) / 2, 15);
            }
            return distortionLevel;
        }
 private int reverbLevelForShip(Ship ship)
 {
     // This is not affected by ship parameters
     return (int)(80 * ((decimal)configuration.EffectsLevel) / ((decimal)100));
 }