public void Say(Commander commander, Ship ship, string script)
        {
            string shipScript;
            if (ship == null || ship.Name == null || ship.Name.Trim().Length == 0)
            {
                shipScript = "your ship";
            }
            else if (ship.PhoneticName == null || ship.PhoneticName.Trim().Length == 0)
            {
                shipScript = ship.Name;
            }
            else
            {
                shipScript = "<phoneme alphabet=\"ipa\" ph=\"" + ship.PhoneticName + "\">" + ship.Name + "</phoneme>";
            }
            script = script.Replace("$=", shipScript);

            string cmdrScript;
            if (commander == null || commander.Name == null || commander.Name.Trim().Length == 0)
            {
                cmdrScript = "commander";
            }
            else if (commander.PhoneticName == null || commander.PhoneticName.Trim().Length == 0)
            {
                cmdrScript = "commander " + commander.Name;
            }
            else
            {
                cmdrScript = "commander <phoneme alphabet=\"ipa\" ph=\"" + commander.PhoneticName + "\">" + commander.Name + "</phoneme>";
            }
            script = script.Replace("$-", cmdrScript);

            Speak(script, null, echoDelayForShip(ship), distortionLevelForShip(ship), chorusLevelForShip(ship), reverbLevelForShip(ship), 0, false);
        }
 /// <summary>Obtain details of a ship given its Elite ID</summary>
 public static Ship ShipFromEliteID(long id)
 {
     Ship Ship = new Ship();
     Ship Template;
     if (ShipsByEliteID.TryGetValue(id, out Template))
     {
         Ship.Model = Template.Model;
         Ship.Size = Template.Size;
     }
     return Ship;
 }
        /// <summary>Obtain details of a ship given its Elite ID</summary>
        public static Ship ShipFromEliteID(long id)
        {
            Ship Ship = new Ship();
            Ship Template;
            if (ShipsByEliteID.TryGetValue(id, out Template))
            {
                Ship.EDID = Template.EDID;
                Ship.Model = Template.Model;
                Ship.Size = Template.Size;
            }
            // All ships default to 100% health
            Ship.Health = 100;

            return Ship;
        }
 /// <summary>Obtain details of a ship given its model</summary>
 public static Ship ShipFromModel(string model)
 {
     Ship Ship = new Ship();
     Ship Template;
     if (ShipsByModel.TryGetValue(model, out Template))
     {
         Ship.Model = Template.Model;
         Ship.Size = Template.Size;
     }
     else
     {
         Ship.Model = model;
     }
     return Ship;
 }
 public void Receive(Commander commander, Ship ship, string script)
 {
     if (ship == null)
     {
         script = script.Replace("$=", "Unidentified ship");
     }
     else if (ship.CallSign == null)
     {
         script = script.Replace("$=", "Unidentified " + Translations.ShipModel(ship.Model));
     }
     else
     {
         script = script.Replace("$=", "" + ship.Model + " " + Translations.CallSign(ship.CallSign));
     }
     Speak(script, null, echoDelayForShip(ship), distortionLevelForShip(ship), chorusLevelForShip(ship), reverbLevelForShip(ship), 0, true);
 }
        public static string ShipUri(Ship ship)
        {
            string enableds = "";
            string priorities = "";
            string uri = "http://coriolis.io/outfit/";
            uri += shipModels[ship.Model];
            uri += "/";
            uri += ShipBulkheads(ship.Bulkheads.Name);
            enableds += "1";
            priorities += "4";
            uri += ship.PowerPlant.Class + ship.PowerPlant.Grade;
            enableds += "1";
            priorities += "0";
            uri += ship.Thrusters.Class + ship.Thrusters.Grade;
            enableds += ship.Thrusters.Enabled ? "1" : "0";
            priorities += ship.Thrusters.Priority;
            uri += ship.FrameShiftDrive.Class + ship.FrameShiftDrive.Grade;
            enableds += ship.FrameShiftDrive.Enabled ? "1" : "0";
            priorities += ship.FrameShiftDrive.Priority;
            uri += ship.LifeSupport.Class + ship.LifeSupport.Grade;
            enableds += ship.LifeSupport.Enabled ? "1" : "0";
            priorities += ship.LifeSupport.Priority;
            uri += ship.PowerDistributor.Class + ship.PowerDistributor.Grade;
            enableds += ship.PowerDistributor.Enabled ? "1" : "0";
            priorities += ship.PowerDistributor.Priority;
            uri += ship.Sensors.Class + ship.Sensors.Grade;
            enableds += ship.Sensors.Enabled ? "1" : "0";
            priorities += ship.Sensors.Priority;
            uri += ship.FuelTank.Class + ship.FuelTank.Grade;
            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;
                    }
                }
            }
            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;
                    }
                }

            }

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

            return uri;
        }
 private int reverbLevelForShip(Ship ship)
 {
     // This is not affected by ship parameters
     return (int)(80 * ((decimal)configuration.EffectsLevel) / ((decimal)100));
 }
 private int echoDelayForShip(Ship ship)
 {
     // this is affected by ship size
     int echoDelay = 50; // Default
     if (ship != null)
     {
         switch (ship.Size)
         {
             case ShipSize.Small:
                 echoDelay = 50;
                 break;
             case ShipSize.Medium:
                 echoDelay = 100;
                 break;
             case ShipSize.Large:
                 echoDelay = 200;
                 break;
             case ShipSize.Huge:
                 echoDelay = 400;
                 break;
         }
     }
     return echoDelay;
 }
        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 static void AugmentShipInfo(Ship ship, List<Ship> storedShips)
        {
            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.CallSign = shipConfig.CallSign;
                ship.Role = shipConfig.Role;
            }
            else
            {
                // Doesn't already exist; add a callsign and default role
                ship.CallSign = Ship.generateCallsign();
                ship.Role = ShipRole.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.CallSign = shipConfig.CallSign;
                    storedShip.Role = shipConfig.Role;
                }
                else
                {
                    // Doesn't already exist; add a callsign and default role
                    storedShip.CallSign = Ship.generateCallsign();
                    storedShip.Role = ShipRole.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();
        }
        public static List<Ship> StoredShipsFromProfile(dynamic json, ref Commander commander)
        {
            Ship currentShip = commander.Ship;

            List<Ship> StoredShips = new List<Ship>();

            foreach (dynamic shipJson in json["ships"])
            {
                if (shipJson != null)
                {
                    dynamic ship = shipJson.Value;
                    if (ship != null)
                    {
                        if ((int)ship["id"] != currentShip.LocalId)
                        {
                            Ship Ship = new Ship();

                            if (ship["starsystem"] != null)
                            {
                                // If we have a starsystem it means that the ship is stored
                                Ship.LocalId = ship["id"];
                                Ship.Model = ship["name"];
                                if (shipTranslations.ContainsKey(Ship.Model))
                                {
                                    Ship.Model = shipTranslations[Ship.Model];
                                }

                                Ship.StarSystem = ship["starsystem"]["name"];
                                Ship.Station = ship["station"]["name"];

                                StoredShips.Add(Ship);
                            }
                        }
                    }
                }
            }

            return StoredShips;
        }
        public static Ship ShipFromProfile(dynamic json)
        {
            String Model = json["ship"]["name"];
            if (shipTranslations.ContainsKey(Model))
            {
                Model = shipTranslations[Model];
            }

            Ship Ship = ShipDefinitions.ShipFromModel(Model);
            if (Ship == null)
            {
                Ship = new Ship();
                Ship.Model = Model;
            }

            Ship.LocalId = json["ship"]["id"];

            Ship.Value = (long)json["ship"]["value"]["hull"] + (long)json["ship"]["value"]["modules"];

            Ship.CargoCapacity = (int)json["ship"]["cargo"]["capacity"];
            Ship.CargoCarried = (int)json["ship"]["cargo"]["qty"];

            // Be sensible with health - round it unless it's very low
            decimal Health = (decimal)json["ship"]["health"]["hull"] / 10000;
            if (Health < 5)
            {
                Ship.Health = Math.Round(Health, 1);
            }
            else
            {
                Ship.Health = Math.Round(Health);
            }

            // Obtain the internals
            Ship.Bulkheads = ModuleFromProfile("Armour", json["ship"]["modules"]["Armour"]);
            Ship.PowerPlant = ModuleFromProfile("PowerPlant", json["ship"]["modules"]["PowerPlant"]);
            Ship.Thrusters = ModuleFromProfile("MainEngines", json["ship"]["modules"]["MainEngines"]);
            Ship.FrameShiftDrive = ModuleFromProfile("FrameShiftDrive", json["ship"]["modules"]["FrameShiftDrive"]);
            Ship.LifeSupport = ModuleFromProfile("LifeSupport", json["ship"]["modules"]["LifeSupport"]);
            Ship.PowerDistributor = ModuleFromProfile("PowerDistributor", json["ship"]["modules"]["PowerDistributor"]);
            Ship.Sensors = ModuleFromProfile("Radar", json["ship"]["modules"]["Radar"]);
            Ship.FuelTank = ModuleFromProfile("FuelTank", json["ship"]["modules"]["FuelTank"]);

            // Obtain the hardpoints
            foreach (dynamic module in json["ship"]["modules"])
            {
                if (module.Name.Contains("Hardpoint"))
                {
                    Ship.Hardpoints.Add(HardpointFromProfile(module));
                }
            }

            // Obtain the compartments
            foreach (dynamic module in json["ship"]["modules"])
            {
                if (module.Name.Contains("Slot"))
                {
                    Ship.Compartments.Add(CompartmentFromProfile(module));
                }
            }

            return Ship;
        }