Exemplo n.º 1
0
        /// <summary>
        /// Build a store from a list of variables
        /// </summary>
        private BuiltinStore buildStore(Dictionary <string, Cottle.Value> vars)
        {
            BuiltinStore store = new BuiltinStore();

            // Function to call another script
            store["F"] = new NativeFunction((values) =>
            {
                return(new ScriptResolver(scripts).resolve(values[0].AsString, store, false));
            }, 1);

            // Translation functions
            store["P"] = new NativeFunction((values) =>
            {
                string val         = values[0].AsString;
                string translation = val;
                if (translation == val)
                {
                    translation = Translations.Faction(val);
                }
                if (translation == val)
                {
                    translation = Translations.Power(val);
                }
                if (translation == val)
                {
                    translation = Translations.StarSystem(val);
                }
                if (translation == val)
                {
                    Ship ship = ShipDefinitions.FromModel(val);
                    if (ship != null && ship.EDID > 0)
                    {
                        translation = ship.SpokenModel();
                    }
                }
                if (translation == val)
                {
                    Ship ship = ShipDefinitions.FromEDModel(val);
                    if (ship != null && ship.EDID > 0)
                    {
                        translation = ship.SpokenModel();
                    }
                }
                return(translation);
            }, 1);

            // Boolean constants
            store["true"]  = true;
            store["false"] = false;

            // Helper functions
            store["OneOf"] = new NativeFunction((values) =>
            {
                return(new ScriptResolver(scripts).resolveScript(values[random.Next(values.Count)].AsString, store, false));
            });

            store["Occasionally"] = new NativeFunction((values) =>
            {
                if (random.Next((int)values[0].AsNumber) == 0)
                {
                    return(new ScriptResolver(scripts).resolveScript(values[1].AsString, store, false));
                }
                else
                {
                    return("");
                }
            }, 2);

            store["Humanise"] = new NativeFunction((values) =>
            {
                return(Translations.Humanize(values[0].AsNumber));
            }, 1);

            store["Pause"] = new NativeFunction((values) =>
            {
                return(@"<break time =""" + values[0].AsNumber + @"ms"" />");
            }, 1);

            //
            // Commander-specific functions
            //
            store["ShipName"] = new NativeFunction((values) =>
            {
                int?localId   = (values.Count == 0 ? (int?)null : (int)values[0].AsNumber);
                string model  = (values.Count == 2 ? values[1].AsString : null);
                Ship ship     = findShip(localId, model);
                string result = (ship == null ? "your ship" : ship.SpokenName());
                return(result);
            }, 0, 2);

            store["ShipCallsign"] = new NativeFunction((values) =>
            {
                int?localId = (values.Count == 0 ? (int?)null : (int)values[0].AsNumber);
                Ship ship   = findShip(localId, null);

                string result;
                if (ship != null)
                {
                    if (EDDI.Instance.Cmdr != null && EDDI.Instance.Cmdr.name != null)
                    {
                        // Obtain the first three characters
                        string chars = new Regex("[^a-zA-Z0-9]").Replace(EDDI.Instance.Cmdr.name, "").ToUpperInvariant().Substring(0, 3);
                        result       = ship.SpokenManufacturer() + " " + Translations.CallSign(chars);
                    }
                    else
                    {
                        if (ship.SpokenManufacturer() == null)
                        {
                            result = "unidentified ship";
                        }
                        else
                        {
                            result = "unidentified " + ship.SpokenManufacturer() + " " + ship.SpokenModel();
                        }
                    }
                }
                else
                {
                    result = "unidentified ship";
                }
                return(result);
            }, 0, 1);

            //
            // Obtain definition objects for various items
            //

            store["SecondsSince"] = new NativeFunction((values) =>
            {
                long?date = (long?)values[0].AsNumber;
                if (date == null)
                {
                    return(null);
                }
                long now = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

                return(now - date);
            }, 1);

            store["ShipDetails"] = new NativeFunction((values) =>
            {
                Ship result = ShipDefinitions.FromModel(values[0].AsString);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["CombatRatingDetails"] = new NativeFunction((values) =>
            {
                CombatRating result = CombatRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = CombatRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["TradeRatingDetails"] = new NativeFunction((values) =>
            {
                TradeRating result = TradeRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = TradeRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["ExplorationRatingDetails"] = new NativeFunction((values) =>
            {
                ExplorationRating result = ExplorationRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = ExplorationRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["EmpireRatingDetails"] = new NativeFunction((values) =>
            {
                EmpireRating result = EmpireRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = EmpireRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["FederationRatingDetails"] = new NativeFunction((values) =>
            {
                FederationRating result = FederationRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = FederationRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["SystemDetails"] = new NativeFunction((values) =>
            {
                StarSystem result = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[0].AsString, true);
                setSystemDistanceFromHome(result);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["BodyDetails"] = new NativeFunction((values) =>
            {
                StarSystem system;
                if (values.Count == 1)
                {
                    // Current system
                    system = EDDI.Instance.CurrentStarSystem;
                }
                else
                {
                    // Named system
                    system = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[1].AsString, true);
                }
                Body result = system != null && system.bodies != null ? system.bodies.FirstOrDefault(v => v.name == values[0].AsString) : null;
                if (result != null && result.type == "Star" && result.chromaticity == null)
                {
                    // Need to set our internal extras for the star
                    result.setStellarExtras();
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1, 2);

            store["StationDetails"] = new NativeFunction((values) =>
            {
                if (values.Count == 0)
                {
                    return(null);
                }
                StarSystem system;
                if (values.Count == 1)
                {
                    // Current system
                    system = EDDI.Instance.CurrentStarSystem;
                }
                else
                {
                    // Named system
                    system = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[1].AsString, true);
                }
                Station result = system != null && system.stations != null ? system.stations.FirstOrDefault(v => v.name == values[0].AsString) : null;
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1, 2);

            store["SuperpowerDetails"] = new NativeFunction((values) =>
            {
                Superpower result = Superpower.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Superpower.From(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["StateDetails"] = new NativeFunction((values) =>
            {
                State result = State.FromName(values[0].AsString);
                if (result == null)
                {
                    result = State.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["EconomyDetails"] = new NativeFunction((values) =>
            {
                Economy result = Economy.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Economy.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["GovernmentDetails"] = new NativeFunction((values) =>
            {
                Government result = Government.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Government.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["SecurityLevelDetails"] = new NativeFunction((values) =>
            {
                SecurityLevel result = SecurityLevel.FromName(values[0].AsString);
                if (result == null)
                {
                    result = SecurityLevel.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["MaterialDetails"] = new NativeFunction((values) =>
            {
                Material result = Material.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Material.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["Distance"] = new NativeFunction((values) =>
            {
                return((decimal)Math.Round(Math.Sqrt(Math.Pow((double)(values[0].AsNumber - values[3].AsNumber), 2)
                                                     + Math.Pow((double)(values[1].AsNumber - values[4].AsNumber), 2)
                                                     + Math.Pow((double)(values[2].AsNumber - values[5].AsNumber), 2)), 2));
            }, 6);

            store["SetState"] = new NativeFunction((values) =>
            {
                string name        = values[0].AsString.ToLowerInvariant().Replace(" ", "_");
                Cottle.Value value = values[1];
                if (value.Type == Cottle.ValueContent.Boolean)
                {
                    EDDI.Instance.State[name] = value.AsBoolean;
                    store["state"]            = buildState();
                }
                else if (value.Type == Cottle.ValueContent.Number)
                {
                    EDDI.Instance.State[name] = value.AsNumber;
                    store["state"]            = buildState();
                }
                else if (value.Type == Cottle.ValueContent.String)
                {
                    EDDI.Instance.State[name] = value.AsString;
                    store["state"]            = buildState();
                }
                // Ignore other possibilities
                return("");
            }, 2);

            // Variables
            foreach (KeyValuePair <string, Cottle.Value> entry in vars)
            {
                store[entry.Key] = entry.Value;
            }

            return(store);
        }
        /// <summary>
        /// Build a store from a list of variables
        /// </summary>
        private BuiltinStore buildStore(Dictionary <string, Cottle.Value> vars)
        {
            BuiltinStore store = new BuiltinStore();

            // Function to call another script
            store["F"] = new NativeFunction((values) =>
            {
                return(new ScriptResolver(scripts).resolve(values[0].AsString, store));
            }, 1);

            // Translation functions
            store["P"] = new NativeFunction((values) =>
            {
                string val         = values[0].AsString;
                string translation = val;
                if (translation == val)
                {
                    translation = Translations.Faction(val);
                }
                if (translation == val)
                {
                    translation = Translations.Power(val);
                }
                if (translation == val)
                {
                    translation = Translations.StarSystem(val);
                }
                return(translation);
            }, 1);

            // Helper functions
            store["OneOf"] = new NativeFunction((values) =>
            {
                return(new ScriptResolver(scripts).resolveScript(values[random.Next(values.Count)].AsString, store));
            });

            store["Occasionally"] = new NativeFunction((values) =>
            {
                if (random.Next((int)values[0].AsNumber) == 0)
                {
                    return(new ScriptResolver(scripts).resolveScript(values[1].AsString, store));
                }
                else
                {
                    return("");
                }
            }, 2);

            store["Humanise"] = new NativeFunction((values) =>
            {
                return(Translations.Humanize(values[0].AsNumber));
            }, 1);

            store["Pause"] = new NativeFunction((values) =>
            {
                return(@"<break time =""" + values[0].AsNumber + @"ms"" />");
            }, 1);

            //
            // Commander-specific functions
            //
            store["ShipName"] = new NativeFunction((values) =>
            {
                int?localId   = (values.Count == 0 ? (int?)null : (int)values[0].AsNumber);
                string model  = (values.Count == 2 ? values[1].AsString : null);
                Ship ship     = findShip(localId, model);
                string result = (ship == null ? "your ship" : ship.SpokenName());
                return(result);
            }, 0, 2);

            store["ShipCallsign"] = new NativeFunction((values) =>
            {
                int?localId = (values.Count == 0 ? (int?)null : (int)values[0].AsNumber);
                Ship ship   = findShip(localId, null);

                string result;
                if (ship != null)
                {
                    if (EDDI.Instance.Cmdr != null && EDDI.Instance.Cmdr.name != null)
                    {
                        // Obtain the first three characters
                        string chars = new Regex("[^a-zA-Z0-9]").Replace(EDDI.Instance.Cmdr.name, "").ToUpperInvariant().Substring(0, 3);
                        result       = ship.SpokenManufacturer() + " " + Translations.CallSign(chars);
                    }
                    else
                    {
                        if (ship.SpokenManufacturer() == null)
                        {
                            result = "unidentified ship";
                        }
                        else
                        {
                            result = "unidentified " + ship.SpokenManufacturer() + " " + ship.SpokenModel();
                        }
                    }
                }
                else
                {
                    result = "unidentified ship";
                }
                return(result);
            }, 0, 1);

            //
            // Obtain definition objects for various items
            //

            store["ShipDetails"] = new NativeFunction((values) =>
            {
                int?localId = (values.Count == 0 ? (int?)null : (int)values[0].AsNumber);
                Ship result = findShip(localId, null);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 0, 1);

            store["CombatRatingDetails"] = new NativeFunction((values) =>
            {
                CombatRating result = CombatRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = CombatRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["TradeRatingDetails"] = new NativeFunction((values) =>
            {
                TradeRating result = TradeRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = TradeRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["ExplorationRatingDetails"] = new NativeFunction((values) =>
            {
                ExplorationRating result = ExplorationRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = ExplorationRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["EmpireRatingDetails"] = new NativeFunction((values) =>
            {
                EmpireRating result = EmpireRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = EmpireRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["FederationRatingDetails"] = new NativeFunction((values) =>
            {
                FederationRating result = FederationRating.FromName(values[0].AsString);
                if (result == null)
                {
                    result = FederationRating.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["SystemDetails"] = new NativeFunction((values) =>
            {
                StarSystem result = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[0].AsString, true);
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["StationDetails"] = new NativeFunction((values) =>
            {
                if (values.Count == 0)
                {
                    return(null);
                }
                StarSystem system;
                if (values.Count == 1)
                {
                    // Current system
                    system = EDDI.Instance.CurrentStarSystem;
                }
                else
                {
                    system = StarSystemSqLiteRepository.Instance.GetOrCreateStarSystem(values[1].AsString, true);
                }
                Station result = system != null && system.stations != null ? system.stations.FirstOrDefault(v => v.name == values[0].AsString) : null;
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1, 2);

            store["SuperpowerDetails"] = new NativeFunction((values) =>
            {
                Superpower result = Superpower.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Superpower.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["StateDetails"] = new NativeFunction((values) =>
            {
                State result = State.FromName(values[0].AsString);
                if (result == null)
                {
                    result = State.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["EconomyDetails"] = new NativeFunction((values) =>
            {
                Economy result = Economy.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Economy.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["GovernmentDetails"] = new NativeFunction((values) =>
            {
                Government result = Government.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Government.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["SecurityLevelDetails"] = new NativeFunction((values) =>
            {
                SecurityLevel result = SecurityLevel.FromName(values[0].AsString);
                if (result == null)
                {
                    result = SecurityLevel.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            store["MaterialDetails"] = new NativeFunction((values) =>
            {
                Material result = Material.FromName(values[0].AsString);
                if (result == null)
                {
                    result = Material.FromEDName(values[0].AsString);
                }
                return(result == null ? new ReflectionValue(new object()) : new ReflectionValue(result));
            }, 1);

            // Variables
            foreach (KeyValuePair <string, Cottle.Value> entry in vars)
            {
                store[entry.Key] = entry.Value;
            }

            return(store);
        }
Exemplo n.º 3
0
 public void TestCallsign()
 {
     SpeechService.Instance.Say(ShipDefinitions.FromEliteID(128049309), Translations.CallSign("GAB-1655"), true);
 }
        public void TestCallsign()
        {
            SpeechService SpeechService = new SpeechService();

            SpeechService.Say(null, ShipDefinitions.ShipFromEliteID(128049309), Translations.CallSign("GAB-1655"));
        }
 public void TestTranslateCallsigns()
 {
     Assert.AreEqual("<phoneme alphabet=\"ipa\" ph=\"ɡɒlf\">golf</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈælfə\">alpha</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈeksˈrei\">x-ray</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈwʌn\">one</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈzɪərəʊ\">zero</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈnaɪnər\">niner</phoneme> <phoneme alphabet=\"ipa\" ph=\"ˈfoʊ.ər\">fawer</phoneme>", Translations.CallSign("GAX-1094"));
 }
Exemplo n.º 6
0
        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.LastStation == null ? null : EDDI.Instance.LastStation.outfitting, prefix + " bulkheads", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.powerplant, prefix + " power plant", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.powerplant, EDDI.Instance.LastStation == null ? null : EDDI.Instance.LastStation.outfitting, prefix + " power plant", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.thrusters, prefix + " thrusters", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.thrusters, EDDI.Instance.LastStation == null ? null : EDDI.Instance.LastStation.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.LastStation == null ? null : EDDI.Instance.LastStation.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.LastStation == null ? null : EDDI.Instance.LastStation.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.LastStation == null ? null : EDDI.Instance.LastStation.outfitting, prefix + " power distributor", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.sensors, prefix + " sensors", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.sensors, EDDI.Instance.LastStation == null ? null : EDDI.Instance.LastStation.outfitting, prefix + " sensors", ref vaProxy);
                setShipModuleValues(ship == null ? null : ship.fueltank, prefix + " fuel tank", ref vaProxy);
                setShipModuleOutfittingValues(ship == null ? null : ship.fueltank, EDDI.Instance.LastStation == null ? null : EDDI.Instance.LastStation.outfitting, prefix + " fuel tank", ref vaProxy);

                // 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.LastStation == null ? null : EDDI.Instance.LastStation.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.LastStation == null ? null : EDDI.Instance.LastStation.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");
        }
Exemplo n.º 7
0
 public void TestTranslateCallsigns()
 {
     Assert.AreEqual("golf, alpha, x-ray, one, zero, niner, fawer", Translations.CallSign("GAX-1094"));
 }