private void landedVessel(CelestialBody crashBody, Vessel vessel, Vessel crashVessel)
 {
     Log("And it is landed");
     if (vessel.loaded)
     {
         List <Seismometer> seismographs = vessel.FindPartModulesImplementing <Seismometer>();
         if (seismographs.Count != 0)
         {
             Log("Found seismographs");
             ImpactScienceData data = createSeismicData(crashBody, crashVessel, seismographs[0].part.flightID);
             ImpactCoordinator.getInstance().bangListeners.Fire(data);
             seismographs[0].addExperiment(data);
         }
     }
     else
     {
         List <ProtoPartSnapshot> parts = vessel.protoVessel.protoPartSnapshots;
         foreach (ProtoPartSnapshot snap in parts)
         {
             foreach (ProtoPartModuleSnapshot mod in snap.modules)
             {
                 if (mod.moduleName == "Seismometer")
                 {
                     Log("Found seismographs");
                     ImpactScienceData data = createSeismicData(crashBody, crashVessel, snap.flightID);
                     ImpactCoordinator.getInstance().bangListeners.Fire(data);
                     Seismometer.NewResult(mod.moduleValues, data);
                     return;
                 }
             }
         }
     }
 }
Beispiel #2
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);
            }
        }
        private void orbitingVessel(CelestialBody crashBody, Vessel observer, Vessel crashVessel)
        {
            Log("And it is orbiting");
            Log("CelestialBody is at " + crashBody.position);
            Log("Crash vessel is at" + crashVessel.CoM);
            Log("Observer is at" + observer.CoM);
            Vector3d crash = crashVessel.CoM;

            crash = crashVessel.CoM - crashBody.position;
            Log("crashRelaticeTocentre =" + crash);
            Vector3d orbVec   = observer.CoM - crashBody.position;
            Vector3d sightVec = (orbVec - crash);
            double   angle    = Vector3d.Angle(crash, sightVec);

            Log("Sight=" + sightVec);
            Log("sight angle = " + angle + " degrees");
            Log("Distance between them =" + sightVec.magnitude);

            if (angle < 90)
            {
                Log("Vessel is visible");
                if (observer.loaded)
                {
                    List <Spectrometer> spectrometers = observer.FindPartModulesImplementing <Spectrometer>();
                    if (spectrometers.Count != 0)
                    {
                        Log("Found spectrometers");
                        ImpactScienceData data = createSpectralData(crashBody, crashVessel, spectrometers[0].part.flightID);
                        ImpactCoordinator.getInstance().bangListeners.Fire(data);
                        spectrometers[0].addExperiment(data);
                    }
                }
                else
                {
                    List <ProtoPartSnapshot> parts = observer.protoVessel.protoPartSnapshots;
                    foreach (ProtoPartSnapshot snap in parts)
                    {
                        foreach (ProtoPartModuleSnapshot mod in snap.modules)
                        {
                            if (mod.moduleName == "Spectrometer")
                            {
                                Log("Found spectrometers");
                                ImpactScienceData data = createSpectralData(crashBody, crashVessel, snap.flightID);
                                Log("about to call listeners");
                                ImpactCoordinator.getInstance().bangListeners.Fire(data);
                                Log("About to call newresult");
                                Spectrometer.NewResult(mod.moduleValues, data);
                                return;
                            }
                        }
                    }
                }
            }
        }
        private void nearAsteroidVessel(Vessel observer, Vessel crashVessel, Vessel asteroid, CelestialBody crashBody)
        {
            Log("observer is orbiting ");
            Log("observer is at " + observer.CoM);
            Log("Crash vessel is at" + crashVessel.CoM);
            Vector3d sightVec = observer.CoM - crashVessel.CoM;

            Log("Distance between them =" + sightVec.magnitude);


            if (sightVec.magnitude < 5e5)
            {
                //observer is in range (500km)
                Log("It is in range =" + (sightVec).magnitude);
                if (observer.loaded)
                {
                    List <Spectrometer> spectrometers = observer.FindPartModulesImplementing <Spectrometer>();
                    if (spectrometers.Count != 0)
                    {
                        Log("Found loaded spectrometers");
                        ImpactScienceData data = createAsteroidSpectralData(crashBody, asteroid, crashVessel, spectrometers[0].part.flightID);
                        ImpactCoordinator.getInstance().bangListeners.Fire(data);
                        spectrometers[0].addExperiment(data);
                    }
                }
                else
                {
                    List <ProtoPartSnapshot> parts = observer.protoVessel.protoPartSnapshots;
                    foreach (ProtoPartSnapshot snap in parts)
                    {
                        foreach (ProtoPartModuleSnapshot mod in snap.modules)
                        {
                            if (mod.moduleName == "Spectrometer")
                            {
                                Log("Found unloaded spectrometers");
                                ImpactScienceData data = createAsteroidSpectralData(crashBody, asteroid, crashVessel, snap.flightID);
                                ImpactCoordinator.getInstance().bangListeners.Fire(data);
                                Spectrometer.NewResult(mod.moduleValues, data);
                                return;
                            }
                        }
                    }
                }
            }
        }
Beispiel #5
0
 protected override void OnUnregister()
 {
     base.OnUnregister();
     ImpactCoordinator.getInstance().scienceListeners.Remove(OnScience);
 }
Beispiel #6
0
 protected override void OnUnregister()
 {
     base.OnUnregister();
     ImpactCoordinator.getInstance().bangListeners.Remove(OnBang);
 }
 public void scienceToKSC(ImpactScienceData data)
 {
     ImpactCoordinator.getInstance().scienceListeners.Fire(data);
 }