public void gatherScience(bool silent = false) { int level = handler.getMaxLevel(instantResults); if (level <= 0) { return; } ScienceData data = SEP_Utilities.getScienceData(handler, handler.getExperimentLevel(instantResults), level); if (data == null) { SEP_Utilities.log("Null Science Data returned; something went wrong here...", logLevels.warning); return; } GameEvents.OnExperimentDeployed.Fire(data); if (handler == null) { return; } handler.GetData().Add(data); if (silent) { transferToEVA(); } else { ReviewData(); } }
private bool transmitData(SEP_ExperimentHandler exp, int level, float submittedData, float newData) { ScienceData data = SEP_Utilities.getScienceData(exp, exp.getExperimentLevel(level), level); if (exp.vessel.loaded) { IScienceDataTransmitter bestTransmitter = ScienceUtil.GetBestTransmitter(exp.vessel); if (bestTransmitter != null) { ScienceExperiment e = exp.getExperimentLevel(level); float transmitterCost = getLoadedTransmitterCost(bestTransmitter); float ecCost = newData * e.dataScale * transmitterCost; if (ecCost > SEP_Utilities.getTotalVesselEC(exp.vessel)) { if (!dataOnboard(exp, level)) { SEP_Utilities.log("Not enough power for transmissionon this vessel: {1}; saving data: {0}", logLevels.log, data.title, exp.vessel.vesselName); exp.addData(data); if (exp.host != null) { exp.host.Events["ReviewDataEvent"].active = true; exp.host.Events["TransferDataEvent"].active = exp.host.hasContainer; exp.host.Events["CollectData"].active = true; if (exp.host.Controller != null) { exp.host.Controller.setCollectEvent(); } } } return(false); } SEP_Utilities.log("Sending data to vessel comms: {0}", logLevels.log, data.title); bestTransmitter.TransmitData(new List <ScienceData> { data }); return(true); } else { if (!dataOnboard(exp, level)) { SEP_Utilities.log("No Comms Devices on this vessel: {1}. Cannot Transmit Data; saving data: {0}", logLevels.log, data.title, exp.vessel.vesselName); exp.addData(data); if (exp.host != null) { exp.host.Events["ReviewDataEvent"].active = true; exp.host.Events["TransferDataEvent"].active = exp.host.hasContainer; exp.host.Events["CollectData"].active = true; if (exp.host.Controller != null) { exp.host.Controller.setCollectEvent(); } } } return(false); } } else { List <ProtoPartSnapshot> transmitters = getProtoTransmitters(exp.vessel.protoVessel); float?transmitterCost = getBestTransmitterCost(transmitters); if (transmitterCost == null) { if (!dataOnboard(exp, level)) { SEP_Utilities.log("No Comms Devices on this vessel: {1}. Cannot Transmit Data; saving data: {0}", logLevels.log, data.title, exp.vessel.protoVessel.vesselName); exp.addData(data); } return(false); } //SEP_Utilities.log("Transmission Score: {0:N4}EC", logLevels.warning, transmitterCost); ScienceExperiment e = exp.getExperimentLevel(level); float ecCost = newData * e.dataScale * (float)transmitterCost; //SEP_Utilities.log("Transmission Cost: {0:N4}EC", logLevels.warning, ecCost); if (ecCost > SEP_Utilities.getTotalVesselEC(exp.vessel.protoVessel)) { if (!dataOnboard(exp, level)) { SEP_Utilities.log("Not enough electricity on this vessel: {1}. Cannot Transmit Data; saving data: {0}", logLevels.log, data.title, exp.vessel.protoVessel.vesselName); exp.addData(data); } return(false); } ScienceSubject sub = SEP_Utilities.checkAndUpdateRelatedSubjects(exp, level, newData, submittedData); if (sub == null) { return(false); } ResearchAndDevelopment.Instance.SubmitScienceData(newData * sub.dataScale, sub, 1, exp.vessel.protoVessel); if (exp.vessel.HasValidContractObjectives(new List <string> { "Generator" })) { consumeResources(exp.vessel.protoVessel, ecCost); } exp.submittedData += (newData - submittedData); return(true); } }
private void experimentCheck(double time) { int l = experiments.Count; //if (l > 0) //SEP_Utilities.log("Performing SEP background check on {0} experiments at time: {1:N0}", logLevels.log, l , time); for (int i = 0; i < l; i++) { List <SEP_ExperimentHandler> modules = experiments.At(i); int c = modules.Count; for (int j = 0; j < c; j++) { SEP_ExperimentHandler m = modules[j]; if (m == null) { continue; } if (!m.loaded) { continue; } if (!m.vessel.Landed) { continue; } if (!m.experimentRunning) { continue; } if (m.usingECResource && !m.vessel.loaded) { if (!m.vessel.HasValidContractObjectives(new List <string> { "Generator" })) { continue; } } if (m.vessel.loaded) { if (m.host != null && m.host.Controller != null) { if (m.host.vessel != m.host.Controller.vessel) { continue; } } else { continue; } } double t = m.experimentTime; float calib = m.calibration; if (usingCommNet) { if (m.vessel.Connection != null) { float signal = (float)m.vessel.Connection.SignalStrength - 0.5f; if (signal < 0) { signal /= 2; } float bonus = calib * signal; calib += bonus; } } t /= calib; double length = time - m.lastBackgroundCheck; m.lastBackgroundCheck = time; double days = length / 21600; if (days < t) { double n = days / t; //SEPUtilities.log("Updating SEP Experiment Handler [{0}]: Add {1:P6}", logLevels.warning, m.experimentTitle, n); m.completion += (float)n; } else { m.completion = 1; } float max = m.getMaxCompletion(); if (max <= 0.5f) { if (m.completion >= 0.5f) { m.completion = 0.5f; } } else if (max <= 0.75f) { if (m.completion >= 0.75f) { m.completion = 0.75f; } } else { if (m.completion >= 1f) { m.completion = 1f; } } bool transmitted = false; m.submittedData = m.getSubmittedData(); if (m.canTransmit && m.controllerAutoTransmit && transmissionUpgrade) { transmitted = checkTransmission(m); } else { int level = m.getMaxLevel(false); if (!dataOnboard(m, level)) { m.addData(SEP_Utilities.getScienceData(m, m.getExperimentLevel(level), level)); if (m.vessel.loaded && m.host != null) { m.host.Events["ReviewDataEvent"].active = true; m.host.Events["TransferDataEvent"].active = m.host.hasContainer; m.host.Events["CollectData"].active = true; if (m.host.Controller != null) { m.host.Controller.setCollectEvent(); } } } } if (transmitted) { m.clearData(); } if (m.completion >= max) { m.experimentRunning = false; if (m.vessel.loaded && m.host != null) { int count = m.GetScienceCount(); m.host.Events["ReviewDataEvent"].active = !transmitted && count > 0; m.host.Events["TransferDataEvent"].active = !transmitted && count > 0 && m.host.hasContainer; m.host.Events["CollectData"].active = !transmitted && count > 0; m.host.PauseExperiment(); if (m.host.Controller != null) { m.host.Controller.setCollectEvent(); } } } } } }
private bool transmitData(SEP_ExperimentHandler exp, int level, float submittedData, float newData) { if (exp.vessel.loaded) { List <IScienceDataTransmitter> tranList = exp.vessel.FindPartModulesImplementing <IScienceDataTransmitter>(); ScienceData data = SEP_Utilities.getScienceData(exp, exp.getExperimentLevel(level), level); if (tranList.Count > 0) { SEP_Utilities.log("Sending data to vessel comms. {0} devices to choose from. Will try to pick the best one", logLevels.log, tranList.Count); tranList.OrderBy(ScienceUtil.GetTransmitterScore).First().TransmitData(new List <ScienceData> { data }); return(true); } else { exp.addData(data); if (exp.vessel.loaded && exp.host != null) { exp.host.Events["ReviewDataEvent"].active = true; exp.host.Events["CollectData"].active = true; if (exp.host.Controller != null) { exp.host.Controller.setCollectEvent(); } } return(false); } } else { List <ProtoPartSnapshot> transmitters = getProtoTransmitters(exp.vessel.protoVessel); float?transmitterCost = getBestTransmitterCost(transmitters); if (transmitterCost == null) { exp.addData(SEP_Utilities.getScienceData(exp, exp.getExperimentLevel(level), level)); return(false); } //SEPUtilities.log("Transmission Score: {0:N4}EC", logLevels.warning, transmitterCost); ScienceExperiment e = exp.getExperimentLevel(level); float ecCost = newData * e.dataScale * (float)transmitterCost; //SEPUtilities.log("Transmission Cost: {0:N4}EC", logLevels.warning, ecCost); if (ecCost > SEP_Utilities.getTotalVesselEC(exp.vessel.protoVessel)) { exp.addData(SEP_Utilities.getScienceData(exp, exp.getExperimentLevel(level), level)); return(false); } ScienceSubject sub = SEP_Utilities.checkAndUpdateRelatedSubjects(exp, level, newData, submittedData); if (sub == null) { return(false); } ResearchAndDevelopment.Instance.SubmitScienceData(newData * sub.dataScale, sub, 1, exp.vessel.protoVessel); List <string> generators = FinePrint.ContractDefs.GetModules("Power"); if (!FinePrint.Utilities.VesselUtilities.VesselHasAnyModules(generators, exp.vessel)) { consumeResources(exp.vessel.protoVessel, ecCost); } exp.submittedData += (newData - submittedData); return(true); } }
private void experimentCheck(double time) { int l = experiments.Count; if (l > 0) { SEP_Utilities.log("Performing SEP background check on {0} experiments at time: {1:N0}", logLevels.log, l, time); } for (int i = 0; i < l; i++) { List <SEP_ExperimentHandler> modules = experiments.ElementAt(i).Value; int c = modules.Count; for (int j = 0; j < c; j++) { SEP_ExperimentHandler m = modules[j]; if (m == null) { continue; } if (!m.loaded) { continue; } if (!m.experimentRunning) { continue; } if (m.usingECResource && !m.vessel.loaded) { List <string> generators = FinePrint.ContractDefs.GetModules("Power"); if (!FinePrint.Utilities.VesselUtilities.VesselHasAnyModules(generators, m.vessel)) { continue; } } if (m.vessel.loaded) { if (m.host != null && m.host.Controller != null) { if (m.host.vessel != m.host.Controller.vessel) { continue; } } else { continue; } } double t = m.experimentTime; t /= m.calibration; double length = time - m.lastBackgroundCheck; m.lastBackgroundCheck = time; double days = length / 21600; if (days < t) { double n = days / t; //SEPUtilities.log("Updating SEP Experiment Handler [{0}]: Add {1:P6}", logLevels.warning, m.experimentTitle, n); m.completion += (float)n; } else { m.completion = 1; } float max = m.getMaxCompletion(); if (max <= 0.5f) { if (m.completion >= 0.5f) { m.completion = 0.5f; } } else if (max <= 0.75f) { if (m.completion >= 0.75f) { m.completion = 0.75f; } } else { if (m.completion >= 1f) { m.completion = 1f; } } bool transmitted = false; m.submittedData = m.getSubmittedData(); if (m.canTransmit && m.controllerAutoTransmit && transmissionUpgrade) { transmitted = checkTransmission(m); } else { int level = m.getMaxLevel(false); float science = m.currentMaxScience(level); if (science > m.submittedData) { bool flag = true; if (m.GetScienceCount() > 0) { ScienceData dat = m.GetData()[0]; ScienceSubject sub = ResearchAndDevelopment.GetSubjectByID(dat.subjectID); if (sub != null) { float d = dat.dataAmount / sub.dataScale; //SEPUtilities.log("Science Data value check: {0:N2} - {1:N2}", logLevels.warning, science, d); if (science <= d) { flag = false; } } else { flag = false; } } if (flag) { m.addData(SEP_Utilities.getScienceData(m, m.getExperimentLevel(level), level)); if (m.vessel.loaded && m.host != null) { m.host.Events["ReviewDataEvent"].active = true; m.host.Events["CollectData"].active = true; if (m.host.Controller != null) { m.host.Controller.setCollectEvent(); } } } } } if (transmitted) { m.clearData(); } if (m.completion >= max) { m.experimentRunning = false; if (m.vessel.loaded && m.host != null) { int count = m.GetScienceCount(); m.host.Events["ReviewDataEvent"].active = !transmitted && count > 0; m.host.Events["CollectData"].active = !transmitted && count > 0; m.host.PauseExperiment(); if (m.host.Controller != null) { m.host.Controller.setCollectEvent(); } } } } } }