Beispiel #1
0
        private static void loadDifficulties()
        {
            ImpactMonitor.Log("Loading difficulties from " + configFile);
            ConfigNode node = ConfigNode.Load(configFile);

            if (node.HasValue("use_spectrum_biomes"))
            {
                useBiomes = bool.Parse(node.GetValue("use_spectrum_biomes"));
            }

            if (node.HasNode("BIOMES_LIST"))
            {
                biomeDifficulties = new Dictionary <CelestialBody, Dictionary <string, int> >();
                foreach (ConfigNode bodyNode in node.GetNodes())
                {
                    String                   bodyName     = bodyNode.GetValue("body");
                    CelestialBody            body         = FlightGlobals.Bodies.Find(b => b.name == bodyName);
                    Dictionary <string, int> difficulties = new Dictionary <string, int>();
                    ConfigNode.ValueList     values       = bodyNode.values;
                    foreach (ConfigNode.Value s in values)
                    {
                        if (s.name == "body")
                        {
                            continue;
                        }
                        difficulties.Add(s.name, int.Parse(s.value));
                    }
                    biomeDifficulties.Add(body, difficulties);
                }
            }
        }
Beispiel #2
0
        protected override List <PossibleContract> pickContracts(IEnumerable <CelestialBody> bodies)
        {
            List <PossibleContract> possible = new List <PossibleContract>();
            double probSum = 0;

            ImpactMonitor.Log("Finding asteroids");
            IEnumerable <Vessel> asteroids = FlightGlobals.Vessels.Where(v => v.vesselType == VesselType.SpaceObject);

            foreach (Vessel asteroid in asteroids)
            {
                ImpactMonitor.Log("asteroid name = " + asteroid.GetName() + " asteroid discovery=" + asteroid.DiscoveryInfo.Level);
                IEnumerable <AsteroidSpectrumContract> contracts = ContractSystem.Instance.GetCurrentContracts <AsteroidSpectrumContract>()
                                                                   .Where(contract => contract.pickedContract.asteroid == asteroid.GetName());
                if (contracts.Count() > 0)
                {
                    continue;                       //only 1 contract of a given type on a given asteroid at once
                }
                contracts = ContractSystem.Instance.GetCurrentContracts <AsteroidSpectrumContract>()
                            .Where(contract => contract.prestige == prestige && contract.ContractState == State.Offered);
                if (contracts.Count() > 0)
                {
                    continue;                       //only 1 contract a given prestige offered at a time
                }
                //Does this asteroid match the correct presige?
                int stars = getAsteroidStars(asteroid);
                if (stars == starRatings[prestige])
                {
                    possible.Add(new PossibleContract(probSum++, asteroid.GetName(), asteroid.orbit.referenceBody));
                }
            }
            return(possible);
        }
Beispiel #3
0
        public void ReviewDataItem(ScienceData sd)
        {
            ImpactMonitor.Log("Reviewing data from seismomenter");
            ScienceLabSearch labSearch = new ScienceLabSearch(null, sd);

            expDialog = ExperimentsResultDialog.DisplayResult(new ExperimentResultDialogPage(part, sd, 1f, 0f, false, "", true, labSearch, DumpData, KeepData, TransmitData, null));
        }
 public static ImpactMonitor getInstance()
 {
     if (instance == null)
     {
         instance = new ImpactMonitor();
         Log("Starting from getInsance");
     }
     return instance;
 }
 public static ImpactMonitor getInstance()
 {
     if (instance == null)
     {
         instance = new ImpactMonitor();
         Log("Starting from getInsance");
     }
     return(instance);
 }
 internal void addExperiment(ImpactScienceData newData)
 {
     //only replace if it is better than any existing results
     if (result == null || newData.dataAmount > result.dataAmount)
     {
         ImpactMonitor.Log("Trying to save impact");
         result = newData;
     }
 }
Beispiel #7
0
        private double pickKE(double stars, ScienceSubject subject, CelestialBody body)
        {
            double scienceCap  = subject.scienceCap;
            double minSci      = (stars - 1) / 3 * scienceCap;
            double maxSci      = stars / 3 * scienceCap;
            double goalScience = minSci + random.NextDouble() * (maxSci - minSci);
            double ke          = ImpactMonitor.translateScienceToKE(goalScience, body, subject);

            return(ke);
        }
Beispiel #8
0
        private void OnBang(ImpactScienceData data)
        {
            if (isComplete)
            {
                ImpactCoordinator.getInstance().bangListeners.Remove(OnBang);
            }
            ImpactMonitor.Log("bang received in " + contract.expectedDataType + " parameter " + data.datatype);
            if (data.datatype != contract.expectedDataType)
            {
                return;
            }
            ScienceSubject subject = ResearchAndDevelopment.GetSubjectByID(data.subjectID);

            bool passed = false;

            switch (contract.expectedDataType)
            {
            case ImpactScienceData.DataTypes.Seismic:
                //check this was the right body and the impact was high enough energy
                passed = (subject.IsFromBody(contract.body) && data.kineticEnergy >= contract.energy);
                break;

            case ImpactScienceData.DataTypes.Spectral:
                //check it is the right body
                if (!subject.IsFromBody(contract.body))
                {
                    break;
                }
                //if a biome is specified  then check the biome matches
                ImpactMonitor.Log("Contract biome =" + contract.biome + " data biome =" + data.biome);
                ImpactMonitor.Log("Contract lat =" + contract.latitude + " data lat =" + data.latitude);
                if (contract.biome != null)
                {
                    passed = data.biome == contract.biome;
                }
                else
                {
                    passed = contract.latitude <= Math.Abs(data.latitude);
                }
                break;

            case ImpactScienceData.DataTypes.Asteroid:
                ImpactMonitor.Log("Contract astreroid =" + contract.asteroid + " data asteroid ="
                                  + data.asteroid + "data.datatype =" + data.datatype + " data asteroid =" + data.asteroid);
                passed = contract.asteroid == data.asteroid;
                break;
            }

            if (passed)
            {
                SetComplete();
                isComplete = true;
                ImpactCoordinator.getInstance().bangListeners.Remove(OnBang);
            }
        }
Beispiel #9
0
 public override String ToString()
 {
     if (body != null)
     {
         return(body.name + "-" + ImpactMonitor.energyFormat(energy) + "-" + biome + "-" + latitude);
     }
     else
     {
         return(asteroid);
     }
 }
 internal static void NewResult(ConfigNode node, ImpactScienceData newData)
 {
     //only replace if it is better than any existing results
     if (node.HasNode("ScienceData"))
     {
         ConfigNode        storedDataNode = node.GetNode("ScienceData");
         ImpactScienceData data           = new ImpactScienceData(storedDataNode);
         if (newData.dataAmount <= data.dataAmount)
         {
             ImpactMonitor.Log("Discarding because better data is already stored");
             return;
         }
     }
     OnSave(node, newData);
 }
Beispiel #11
0
 internal static void NewResult(ConfigNode node, ImpactScienceData newData)
 {
     //only replace if it is better than any existing results
     if (node.HasNode("ScienceData"))
     {
         ConfigNode storedDataNode = node.GetNode("ScienceData");
         ImpactMonitor.Log("loading data");
         ImpactScienceData data = new ImpactScienceData(storedDataNode);
         if (newData.dataAmount < data.dataAmount || newData.kineticEnergy < data.kineticEnergy)
         {
             return;
         }
     }
     OnSave(node, newData);
 }
Beispiel #12
0
        private void OnVesselDestroy(Vessel vessel)
        {
            ImpactMonitor.Log("In astContract onVesselDestroy");
            if (vessel.vesselType == VesselType.SpaceObject && pickedContract != null)
            {
                ImpactMonitor.Log("vessel of type asteroid has been destroyed - checking for active contracts");
                ImpactMonitor.Log("PC=" + pickedContract);
                ImpactMonitor.Log("PC.ast=" + pickedContract.asteroid);
                ImpactMonitor.Log("vesssle=" + vessel);

                if (pickedContract != null && pickedContract.asteroid != null && pickedContract.asteroid == vessel.GetName())
                {
                    ImpactMonitor.Log("the asteroid is the one refered to by this contract");
                    this.Cancel();
                }
            }
        }
        public void TransmitData(ScienceData data)
        {
            expDialog = null;
            List <IScienceDataTransmitter> tranList = vessel.FindPartModulesImplementing <IScienceDataTransmitter>();

            if (tranList.Count > 0 && result != null)
            {
                List <ScienceData> list2 = new List <ScienceData>();

                list2.Add(result);
                tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(list2);
                ImpactMonitor.getInstance().scienceToKSC(result);
                DumpData(result);
            }
            else
            {
                ScreenMessages.PostScreenMessage(Localizer.Format("#autoLOC_Screen_NoTrans"), 4f, ScreenMessageStyle.UPPER_LEFT);
            }
        }
Beispiel #14
0
 protected override string GetTitle()
 {
     if (contract.asteroid != null)
     {
         return(Localizer.Format(asteroidTitle, contract.asteroid));
     }
     if (contract.biome == null)
     {
         if (contract.energy > 0)
         {
             return(Localizer.Format(keTitle, contract.body.GetDisplayName(), ImpactMonitor.energyFormat(contract.energy)));
         }
         else
         {
             return(Localizer.Format(latitudeTitle, contract.body.GetDisplayName(), contract.latitude));
         }
     }
     else
     {
         return(Localizer.Format(biomeTitle, contract.biome, contract.body.GetDisplayName()));
     }
 }
Beispiel #15
0
 protected override string GetTitle()
 {
     return(Localizer.Format("#autoLOC_SeismicContract_Title",
                             ImpactMonitor.energyFormat(pickedContract.energy), pickedContract.body.GetDisplayName()));
 }
 void Stop()
 {
     ImpactMonitor.getInstance().Stop();
 }
Beispiel #17
0
 protected override void OnCompleted()
 {
     ImpactMonitor.Log("Completed contract with id " + randId);
     base.OnCompleted();
 }
Beispiel #18
0
 protected override string GetDescription()
 {
     return(Localizer.Format("#autoLOC_SeismicContract_Blurb", pickedContract.body.GetDisplayName(), ImpactMonitor.energyFormat(pickedContract.energy)));
 }