internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel) { var vsl = FlightGlobals.Vessels.FirstOrDefault(v => v.id.ToString() == sourceVessel.VesselId); double totHabSpace = (LifeSupportSetup.Instance.LSConfig.BaseHabTime * sourceVessel.CrewCap) + sourceVessel.ExtraHabSpace; double totHabMult = sourceVessel.VesselHabMultiplier; double totCurCrew = sourceVessel.NumCrew; double totMaxCrew = sourceVessel.CrewCap; var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vsl, false); foreach (var v in vList) { var curVsl = LifeSupportManager.Instance.FetchVessel(v.id.ToString()); //Hab time starts with our baseline of the crew hab plus extra hab. //We then multiply it out based on the crew ratio, our global multiplier, and the vessel's multipler. //First - crew capacity. totHabSpace += (LifeSupportSetup.Instance.LSConfig.BaseHabTime * curVsl.CrewCap) + curVsl.ExtraHabSpace; totCurCrew += curVsl.NumCrew; totMaxCrew += curVsl.CrewCap; totHabMult += curVsl.VesselHabMultiplier; } totHabMult += USI_GlobalBonuses.Instance.GetHabBonus(vsl.mainBody.flightGlobalsIndex); double habTotal = totHabSpace / totCurCrew * (totHabMult + 1) * LifeSupportSetup.Instance.LSConfig.HabMultiplier; //print(String.Format("THS: {0} TC:{1} THM: {2} HM: {3}", totHabSpace, totCurCrew, totHabMult, LifeSupportSetup.Instance.LSConfig.HabMultiplier)); return(habTotal * (60d * 60d * 6d * 30d)); }
public void FixedUpdate() { if (!HighLogic.LoadedSceneIsFlight) { return; } if (Math.Abs(Planetarium.GetUniversalTime() - lastCheck) < RepairFrequency) { return; } if (part.protoModuleCrew.All(c => c.experienceTrait.TypeName != "Engineer")) { return; } lastCheck = Planetarium.GetUniversalTime(); var nearbyVesselList = LogisticsTools.GetNearbyVessels(RepairRange, true, vessel, false); foreach (var v in nearbyVesselList) { var modList = v.FindPartModulesImplementing <USI_ModuleFieldRepair>(); foreach (var m in modList) { m.FinalizeMaintenance("Automated Maintenance performed on " + m.part.partInfo.title); } } }
internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel, Vessel vsl, out int numSharedVessels) { //In the event that a vessel is not loaded, we just return the cached value. if (!vsl.loaded) { numSharedVessels = 0; return(sourceVessel.CachedHabTime); } double totHabSpace = sourceVessel.ExtraHabSpace; double totHabMult = sourceVessel.VesselHabMultiplier; int totCurCrew = sourceVessel.NumCrew; int totMaxCrew = sourceVessel.CrewCap; numSharedVessels = 0; var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false); var hList = new List <Vessel>(); var vCount = vList.Count; for (int i = 0; i < vCount; ++i) { var v = vList[i]; //Hab time starts with our baseline of the crew hab plus extra hab. //We then multiply it out based on the crew ratio, our global multiplier, and the vessel's multipler. //First - crew capacity. int crewCap = v.GetCrewCapacity(); totMaxCrew += crewCap; totCurCrew += v.GetCrewCount(); if (crewCap > 0) { numSharedVessels++; hList.Add(v); } } totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *totMaxCrew); var hCount = hList.Count; for (int i = 0; i < hCount; ++i) { var v = hList[i]; // Calculate HabSpace and HabMult after we know totCurCrew and totMaxCrew totHabSpace += CalculateVesselHabExtraTime(v); totHabMult *= Math.Min(1, CalculateVesselHabMultiplier(v, totCurCrew)); } totHabMult += USI_GlobalBonuses.Instance.GetHabBonus(vsl.mainBody.flightGlobalsIndex); double habTotal = totHabSpace / (double)totCurCrew * (totHabMult + 1) * LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier; //print(String.Format("THS: {0} TC:{1} THM: {2} HM: {3}", totHabSpace, totCurCrew, totHabMult, LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier)); sourceVessel.CachedHabTime = Math.Max(0, habTotal * LifeSupportUtilities.SecondsPerMonth()); LifeSupportManager.Instance.TrackVessel(sourceVessel); return(sourceVessel.CachedHabTime); }
internal static double GetRecyclerMultiplier(Vessel vessel) { if (!LifeSupportSetup.Instance.LSConfig.EnableRecyclers) { return(1d); } var recyclerCap = 0f; var recyclerTot = 0f; var crewCount = GetColonyCrewCount(vessel); foreach (var r in vessel.FindPartModulesImplementing <ModuleLifeSupportRecycler>()) { if (r.RecyclerIsActive && r.IsActivated) { if (r.RecyclePercent > recyclerCap) { recyclerCap = r.RecyclePercent; } var recPercent = r.RecyclePercent; if (r.CrewCapacity < crewCount) { recPercent *= r.CrewCapacity / (float)crewCount; } recyclerTot += recPercent; } } var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vessel, false); foreach (var v in vList) { foreach (var r in v.FindPartModulesImplementing <ModuleLifeSupportRecycler>()) { if (r.IsActivated && r.RecyclerIsActive) { if (r.RecyclePercent > recyclerCap) { recyclerCap = r.RecyclePercent; } var recPercent = r.RecyclePercent; if (r.CrewCapacity < crewCount) { recPercent *= r.CrewCapacity / (float)crewCount; } recyclerTot += recPercent; } } } //Inverse because this is a multiplier - low is good! double retVal = 1d - (Math.Min(recyclerTot, recyclerCap)); return(retVal); }
private static int GetColonyCrewCount(Vessel vsl) { var crewCount = vsl.GetCrewCount(); var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportSetup.Instance.LSConfig.HabRange, false, vsl, false); foreach (var v in vList) { crewCount += v.GetCrewCount(); } return(crewCount); }
private static int GetColonyCrewCount(Vessel vsl) { var crewCount = vsl.GetCrewCount(); var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false); var count = vList.Count; for (int i = 0; i < count; ++i) { var v = vList[i]; crewCount += v.GetCrewCount(); } return(crewCount); }
private List <ProtoCrewMember> GetNearbyKerbals() { var activeVessel = FlightGlobals.ActiveVessel; if (activeVessel == null) { return(null); } // Make sure we have an eligible terminal nearby var landedSituations = Vessel.Situations.LANDED | Vessel.Situations.PRELAUNCH | Vessel.Situations.SPLASHED; var landedOnly = (activeVessel.situation & landedSituations) == landedSituations; var terminals = LogisticsTools.GetNearbyPartModules <WOLF_TerminalModule>( TERMINAL_RANGE, activeVessel, true, landedOnly); if (terminals == null || terminals.Count < 1) { return(null); } var terminalIds = terminals .Where(t => !string.IsNullOrEmpty(t.TerminalId)) .Select(t => t.TerminalId); var wolfTerminals = _wolf.GetTerminals() .Where(t => terminalIds.Contains(t.Id) && t.Body == _selectedFlight.OriginBody && t.Biome == _selectedFlight.OriginBiome); if (wolfTerminals == null || wolfTerminals.Count() < 1) { return(null); } // Get all nearby vessels var vessels = LogisticsTools .GetNearbyVessels(TERMINAL_RANGE, true, activeVessel, landedOnly); var kerbals = new List <ProtoCrewMember>(); foreach (var vessel in vessels) { var crew = vessel .GetVesselCrew() .Where(c => c.type == ProtoCrewMember.KerbalType.Crew || c.type == ProtoCrewMember.KerbalType.Tourist); kerbals.AddRange(crew); } return(kerbals); }
public void FixedUpdate() { if (!HighLogic.LoadedSceneIsFlight) { return; } if (Math.Abs(Planetarium.GetUniversalTime() - lastCheck) < RepairFrequency) { return; } var engineerCount = 0; var cCount = part.protoModuleCrew.Count; for (int i = 0; i < cCount; ++i) { if (part.protoModuleCrew[i].experienceTrait.TypeName == "Engineer") { engineerCount++; } } if (engineerCount == 0) { return; } lastCheck = Planetarium.GetUniversalTime(); var nearbyVesselList = LogisticsTools.GetNearbyVessels(RepairRange, true, vessel, false); var vCount = nearbyVesselList.Count; for (int i = 0; i < vCount; ++i) { var v = nearbyVesselList[i]; var modList = v.FindPartModulesImplementing <USI_ModuleFieldRepair>(); var mCount = modList.Count; for (int x = 0; x < mCount; ++x) { var m = modList[x]; m.FinalizeMaintenance("Automated Maintenance performed on " + m.part.partInfo.title); } } }
internal static double GetHabChecksum(VesselSupplyStatus sourceVessel, Vessel vsl) { //This routine just returns the total amount of hab factored by the multiplier. //It is used to determine if there was a situation change and thus reset the vessel time. //The main use case would be undocking/docking, or flying into range of a base. //In the event that a vessel is not loaded, return zero. if (!vsl.loaded) { return(0d); } int totMaxCrew = sourceVessel.CrewCap; var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false); var hList = new List <Vessel>(); var vCount = vList.Count; for (int i = 0; i < vCount; ++i) { var v = vList[i]; int crewCap = v.GetCrewCapacity(); totMaxCrew += crewCap; if (crewCap > 0) { hList.Add(v); } } double totHabSpace = sourceVessel.ExtraHabSpace; double totHabMult = CalculateVesselHabMultiplier(vsl, 1); totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *totMaxCrew); var hCount = hList.Count; for (int i = 0; i < hCount; ++i) { var v = hList[i]; totHabSpace += CalculateVesselHabExtraTime(v); totHabMult += CalculateVesselHabMultiplier(v, 1); } return(totHabSpace * (totHabMult + 1)); }
public int GetConstructionPoints() { var points = 0; //Adust parms for our EVA Kerbals var vessels = LogisticsTools.GetNearbyVessels(2000, true, vessel, false); var count = vessels.Count; for (int i = 0; i < count; ++i) { var v = vessels[i]; var kModules = v.FindPartModulesImplementing <ModuleKonstructionHelper>(); foreach (var m in kModules) { points += m.KonstructionPoints; } } return(points); }
internal static double GetTotalHabTime(VesselSupplyStatus sourceVessel, out int numSharedVessels) { var vsl = FlightGlobals.Vessels.FirstOrDefault(v => v.id.ToString() == sourceVessel.VesselId); double totHabSpace = (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *sourceVessel.CrewCap) + sourceVessel.ExtraHabSpace; double totHabMult = sourceVessel.VesselHabMultiplier; int totCurCrew = sourceVessel.NumCrew; int totMaxCrew = sourceVessel.CrewCap; numSharedVessels = 0; var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vsl, false); var hList = new List <Vessel>(); foreach (var v in vList) { //Hab time starts with our baseline of the crew hab plus extra hab. //We then multiply it out based on the crew ratio, our global multiplier, and the vessel's multipler. //First - crew capacity. int crewCap = v.GetCrewCapacity(); totMaxCrew += crewCap; totCurCrew += v.GetCrewCount(); if (crewCap > 0) { numSharedVessels++; hList.Add(v); } } foreach (var v in hList) { // Calculate HabSpace and HabMult after we know totCurCrew and totMaxCrew totHabSpace += (LifeSupportScenario.Instance.settings.GetSettings().BaseHabTime *totMaxCrew) + CalculateVesselHabExtraTime(v); totHabMult += CalculateVesselHabMultiplier(v, totCurCrew); } totHabMult += USI_GlobalBonuses.Instance.GetHabBonus(vsl.mainBody.flightGlobalsIndex); double habTotal = totHabSpace / (double)totCurCrew * (totHabMult + 1) * LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier; //print(String.Format("THS: {0} TC:{1} THM: {2} HM: {3}", totHabSpace, totCurCrew, totHabMult, LifeSupportScenario.Instance.settings.GetSettings().HabMultiplier)); return(Math.Max(0, habTotal * LifeSupportUtilities.SecondsPerMonth())); }
public int GetKerbalQuantity() { var kerbCount = 0; var vessels = LogisticsTools.GetNearbyVessels(2000, true, vessel, false); var count = vessels.Count; for (int i = 0; i < count; ++i) { var v = vessels[i]; if (v.isEVA) { kerbCount++; } else { kerbCount += v.GetCrewCount(); } } return(kerbCount); }
public List <ResourceTransferTargetMetadata> GetResourceTransferTargets() { var nearbyVessels = LogisticsTools.GetNearbyVessels( LOCAL_LOGISTICS_RANGE, true, FlightGlobals.ActiveVessel, false); return(nearbyVessels .Where(v => v.Parts.Any(p => p.Resources.Any(r => !BLACKLIST.Contains(r.resourceName) && ResourceTransferTarget.IsTransferable(r)))) .Select(v => new ResourceTransferTargetMetadata { DisplayName = GetVesselDisplayName(v), Id = v.id.ToString("N"), IsCurrentVessel = v == FlightGlobals.ActiveVessel, Resources = ResourceTransferTarget.GetResourceMetadata(v.Parts), }) .ToList()); }
protected static List <KolonyVessel> GetKolonyVessels(Vessel thisVessel, float range, bool includeThis = true, bool landedOnly = true) { List <KolonyVessel> res = new List <KolonyVessel>(); foreach (var v in LogisticsTools.GetNearbyVessels(range, includeThis, thisVessel, landedOnly)) { KolonyVessel item = new KolonyVessel(); item.name = Misc.Name(v); item.vessel = v; if (v == thisVessel) { item.thisVessel = true; } else { item.thisVessel = false; item.distance = LogisticsTools.GetRange(v, thisVessel); } res.Add(item); } return(res); }
internal static double GetRecyclerMultiplier(Vessel vessel) { if (!LifeSupportScenario.Instance.settings.GetSettings().EnableRecyclers) { return(1d); } var recyclerCap = 0f; var recyclerTot = 0f; var crewCount = GetColonyCrewCount(vessel); var recList = vessel.FindPartModulesImplementing <ModuleLifeSupportRecycler>(); var rmCount = recList.Count; for (int i = 0; i < rmCount; ++i) { var r = recList[i]; if (r.RecyclerIsActive && r.IsActivated) { if (r.AdjustedRecyclePercent > recyclerCap) { recyclerCap = r.AdjustedRecyclePercent; } var recPercent = r.AdjustedRecyclePercent; if (r.CrewCapacity < crewCount) { recPercent *= r.CrewCapacity / (float)crewCount; } recyclerTot += recPercent; } } var vList = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vessel, false); var vCount = vList.Count; for (int i = 0; i < vCount; ++i) { var v = vList[i]; var subRecList = v.FindPartModulesImplementing <ModuleLifeSupportRecycler>(); var subRmCount = subRecList.Count; for (int x = 0; x < subRmCount; ++x) { var r = subRecList[x]; if (r.IsActivated && r.RecyclerIsActive) { if (r.AdjustedRecyclePercent > recyclerCap) { recyclerCap = r.AdjustedRecyclePercent; } var recPercent = r.AdjustedRecyclePercent; if (r.CrewCapacity < crewCount) { recPercent *= r.CrewCapacity / (float)crewCount; } recyclerTot += recPercent; } } } //Inverse because this is a multiplier - low is good! double retVal = 1d - (Math.Min(recyclerTot, recyclerCap)); return(retVal); }
public void Launch() { if (!_activeWarnings.Any(w => w.Value.PreventsAction)) { var activeVessel = FlightGlobals.ActiveVessel; var landedSituations = Vessel.Situations.LANDED | Vessel.Situations.PRELAUNCH | Vessel.Situations.SPLASHED; var landedOnly = (activeVessel.situation & landedSituations) == landedSituations; var vessels = LogisticsTools .GetNearbyVessels(TERMINAL_RANGE, true, activeVessel, landedOnly); var passengers = _passengers.Values.Select(p => p.Name); foreach (var vessel in vessels) { var crew = vessel.GetVesselCrew().ToArray(); foreach (var kerbal in crew) { if (passengers.Contains(kerbal.name)) { if (_selectedFlight.Embark(new Passenger(kerbal))) { vessel.CrewListSetDirty(); var parts = vessel.parts; foreach (var part in parts) { if (part.protoModuleCrew.Contains(kerbal)) { part.RemoveCrewmember(kerbal); break; } } kerbal.rosterStatus = ProtoCrewMember.RosterStatus.Missing; kerbal.SetTimeForRespawn(double.MaxValue); } else { ShowWarning("Could not launch.", false); return; } } } } _selectedFlight.Launch(Planetarium.GetUniversalTime()); _passengers.Clear(); _activeWarnings.Clear(); var metadata = new FlightMetadata() { ArrivalBiome = _selectedFlight.DestinationBiome, ArrivalBody = _selectedFlight.DestinationBody, DepartureBiome = _selectedFlight.OriginBiome, DepartureBody = _selectedFlight.OriginBody, Duration = GetDuration(_selectedFlight), EconomySeats = GetEconomySeats(_selectedFlight), FlightNumber = _selectedFlight.FlightNumber, LuxurySeats = GetLuxurySeats(_selectedFlight), Status = _selectedFlight.FlightStatus, UniqueId = _selectedFlight.UniqueId, }; _window.Launched(metadata); } }
internal static double GetRecyclerMultiplier(Vessel vessel) { if (!LifeSupportScenario.Instance.settings.GetSettings().EnableRecyclers) { return(1d); } var recyclerCap = 0f; var recyclerTot = 0f; var crewCount = GetColonyCrewCount(vessel); var recyclers = vessel.FindConverterAddonsImplementing <USILS_LifeSupportRecyclerConverterAddon>(); for (int i = 0; i < recyclers.Count; ++i) { var recycler = recyclers[i]; if (recycler.IsActive && recycler.IsOperational) { if (recycler.RecyclePercent > recyclerCap) { recyclerCap = recycler.RecyclePercent; } var recPercent = recycler.RecyclePercent; if (recycler.CrewCapacity < crewCount) { recPercent *= recycler.CrewCapacity / (float)crewCount; } recyclerTot += recPercent; } } var vessels = LogisticsTools.GetNearbyVessels((float)LifeSupportScenario.Instance.settings.GetSettings().HabRange, false, vessel, false); for (int i = 0; i < vessels.Count; ++i) { var v = vessels[i]; var nearbyRecyclers = v.FindConverterAddonsImplementing <USILS_LifeSupportRecyclerConverterAddon>(); for (int x = 0; x < nearbyRecyclers.Count; ++x) { var recycler = nearbyRecyclers[x]; if (recycler.IsActive && recycler.IsOperational) { if (recycler.RecyclePercent > recyclerCap) { recyclerCap = recycler.RecyclePercent; } var recPercent = recycler.RecyclePercent; if (recycler.CrewCapacity < crewCount) { recPercent *= recycler.CrewCapacity / (float)crewCount; } recyclerTot += recPercent; } } } //Inverse because this is a multiplier - low is good! double multiplier = 1d - (Math.Min(recyclerTot, recyclerCap)); return(multiplier); }