private void BuildHomes() { ConfigNode KopernicusNode = null; foreach (ConfigNode n in GameDatabase.Instance.GetConfigNodes("Kopernicus")) { KopernicusNode = n; } if (KopernicusNode != null) { foreach (ConfigNode bodyNode in KopernicusNode.GetNodes("Body")) { string t = bodyNode.GetValue("name"); string name = t.Equals("Kerbin") ? FlightGlobals.GetHomeBodyName() : t; if (FlightGlobals.GetBodyByName(name) is CelestialBody body && bodyNode.GetNode("PQS") is ConfigNode pqsNode && pqsNode.GetNode("Mods") is ConfigNode pqsModNode) { foreach (ConfigNode cityNode in pqsModNode.GetNodes("City2")) { bool result = false; if (cityNode.TryGetValue("RACommNetStation", ref result) && result) { BuildHome(cityNode, body); } } } } } }
// We'll piggyback on the base class ConnectToDepotEvent to // handle making the connection on the destination side protected override void ConnectToDepot() { // Check for issues that would prevent deployment var deployCheckResult = CanConnectToDepot(); if (!string.IsNullOrEmpty(deployCheckResult)) { DisplayMessage(deployCheckResult); return; } var destinationBody = vessel.mainBody.name; var destinationBiome = GetVesselBiome(); if (destinationBody == OriginBody && destinationBiome == OriginBiome) { DisplayMessage(INVALID_CONNECTION_MESSAGE); return; } var routePayload = CalculateRoutePayload(); if (!routePayload.HasMinimumPayload(MINIMUM_PAYLOAD)) { DisplayMessage(INSUFFICIENT_PAYLOAD_MESSAGE); return; } try { if (TryNegotiateRoute(destinationBody, destinationBiome, routePayload)) { // Add rewards var homeworld = FlightGlobals.GetHomeBodyName(); if (destinationBody == homeworld && OriginBody != destinationBody) { RewardsManager.AddTransportFunds(routePayload.GetRewards()); } ResetRoute(); } } catch (Exception ex) { DisplayMessage(ex.Message); } }
private bool TryGetBestSituationMatch(string body, string situation, string type, out double situationMult) { var key = $"{body}-{situation}-{type}"; if (Settings.situationValues.TryGetValue(key, out situationMult)) { return(true); } if (body != FlightGlobals.GetHomeBodyName()) { key = $"Other-{situation}-{type}"; if (Settings.situationValues.TryGetValue(key, out situationMult)) { return(true); } } situationMult = 0; return(false); }
private void BuildHomes() { ConfigNode KopernicusNode = null; foreach (ConfigNode n in GameDatabase.Instance.GetConfigNodes("Kopernicus")) { KopernicusNode = n; } if (KopernicusNode != null) { var sb = StringBuilderCache.Acquire(); sb.Append($"{ModTag} Building homes: "); foreach (ConfigNode bodyNode in KopernicusNode.GetNodes("Body")) { string t = bodyNode.GetValue("name"); string name = t.Equals("Kerbin") ? FlightGlobals.GetHomeBodyName() : t; if (FlightGlobals.GetBodyByName(name) is CelestialBody body && bodyNode.GetNode("PQS") is ConfigNode pqsNode && pqsNode.GetNode("Mods") is ConfigNode pqsModNode) { foreach (ConfigNode cityNode in pqsModNode.GetNodes("City2")) { bool result = false; if (cityNode.TryGetValue("RACommNetStation", ref result) && result) { CommNetHome h = BuildHome(cityNode, body); sb.Append($"{h.nodeName} "); } } } } Debug.Log(sb.ToStringAndRelease()); } }
private void kHire() { if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { double myFunds = Funding.Instance.Funds; Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited); Hire.Log.Info("KSI :: Total Funds removed " + costMath()); } for (int i = 0; i < KBulki; i++) { ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew); newKerb.ChangeName(KNames[KGender, i]); switch (KGender) // Sets gender { case 0: newKerb.gender = ProtoCrewMember.Gender.Male; break; case 1: newKerb.gender = ProtoCrewMember.Gender.Female; break; case 2: newKerb.gender = KNames2Gender[i]; break; default: break; } string career = traits.KCareerStrings[KCareer]; // Sets the kerbal's career based on the KCareer switch. KerbalRoster.SetExperienceTrait(newKerb, career); // Hire.Log.Info("KSI :: KIA MIA Stat is: " + KDead); // Hire.Log.Info("KSI :: " + newKerb.experienceTrait.TypeName + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops."); newKerb.rosterStatus = ProtoCrewMember.RosterStatus.Available; newKerb.experience = 0; newKerb.experienceLevel = 0; newKerb.courage = KCourage / 100; newKerb.stupidity = KStupidity / 100; if (KFearless) { newKerb.isBadass = true; } if (KVeteran) { newKerb.veteran = true; } // Hire.Log.Info("PSH :: Status set to Available, courage and stupidity set, fearless trait set."); if (KLevel == 1) { newKerb.flightLog.AddEntry("Training1," + FlightGlobals.GetHomeBodyName()); newKerb.ArchiveFlightLog(); newKerb.experience = 2; newKerb.experienceLevel = 1; // Hire.Log.Info("KSI :: Level set to 1."); } if (KLevel == 2) { newKerb.flightLog.AddEntry("Training2," + FlightGlobals.GetHomeBodyName()); newKerb.ArchiveFlightLog(); newKerb.experience = 8; newKerb.experienceLevel = 2; // Hire.Log.Info("KSI :: Level set to 2."); } if (ACLevel == 5 || kerExp == false) { newKerb.experience = 9999; newKerb.experienceLevel = 5; Hire.Log.Info("KSI :: Level set to 5 - Non-Career Mode default."); } GameEvents.onKerbalAdded.Fire(newKerb); // old gameevent most likely to be used by other mods GameEvents.onKerbalAddComplete.Fire(newKerb); // new gameevent that seems relevant } // Refreshes the AC so that new kerbal shows on the available roster. Hire.Log.Info("PSH :: Hiring Function Completed."); GameEvents.onGUIAstronautComplexDespawn.Fire(); GameEvents.onGUIAstronautComplexSpawn.Fire(); }
private PopupDialog GenerateDialog() { List <DialogGUIBase> guiItems = new List <DialogGUIBase>(); bool vesselIsHome = FlightGlobals.ActiveVessel.mainBody == FlightGlobals.GetHomeBody(); if (FlightGlobals.ActiveVessel == null) { guiItems.Add(new DialogGUILabel("No Vessel Detected")); } else if (vesselIsHome && FlightGlobals.ActiveVessel.situation == Vessel.Situations.ORBITING) { guiItems.Add(new DialogGUILabel(_utilities.SystemNotes, _utilities.CreateNoteStyle())); guiItems.Add(new DialogGUILabel(_utilities.Warnings, _utilities.CreateNoteStyle())); guiItems.Add(new DialogGUIToggle(() => _returnTrip, "Return Trip?", delegate { SetReturnTrip(); })); for (int i = 0; i < _utilities.Planets.Count; i++) { PlanetDeltaV p = _utilities.Planets.ElementAt(i); DialogGUIBase[] horizontal = new DialogGUIBase[4]; horizontal[0] = new DialogGUILabel(p.GetName(), _utilities.GenerateStyle(-1, false)); horizontal[1] = GetDeltaVString(p, "Flyby: "); horizontal[2] = GetDeltaVString(p, "Orbiting: "); if (p.IsHomeWorld && p.SynchronousDv != -1) { horizontal[3] = GetDeltaVString(p, "Synchronous Orbit: "); } else { horizontal[3] = GetDeltaVString(p, "Landing: "); } guiItems.Add(new DialogGUIHorizontalLayout(horizontal)); } guiItems.Add(new DialogGUILabel("*Assuming craft has enough chutes")); } else { guiItems.Add(new DialogGUILabel("No Data Available. Achieve stable orbit around " + FlightGlobals.GetHomeBodyName(), _utilities.GenerateStyle(99999, true))); } guiItems.Add(new DialogGUIButton("Close", () => _utilities.CloseDialog(_uiDialog), false)); return(PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("WhereCanIGoDialog", "", "Where Can I Go", UISkinManager.defaultSkin, _geometry, guiItems.ToArray()), false, UISkinManager.defaultSkin)); }
private void kHire() { System.Random rand = new System.Random(); if (HighLogic.CurrentGame.Mode == Game.Modes.CAREER) { double myFunds = Funding.Instance.Funds; Funding.Instance.AddFunds(-costMath(), TransactionReasons.CrewRecruited); Hire.Log.Info("KSI :: Total Funds removed " + costMath()); } for (int i = 0; i < KBulki; i++) { ProtoCrewMember newKerb = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Crew); newKerb.ChangeName(KNames[KGender, i]); switch (KGender) // Sets gender { case 0: newKerb.gender = ProtoCrewMember.Gender.Male; break; case 1: newKerb.gender = ProtoCrewMember.Gender.Female; break; case 2: newKerb.gender = KNames2Gender[i]; break; default: break; } string career = traits.traitTitles[KCareer].name; // Sets the kerbal's career based on the KCareer switch. KerbalRoster.SetExperienceTrait(newKerb, career); // Hire.Log.Info("KSI :: KIA MIA Stat is: " + KDead); // Hire.Log.Info("KSI :: " + newKerb.experienceTrait.Config.Name + " " + newKerb.name + " has been created in: " + loopcount.ToString() + " loops."); newKerb.rosterStatus = ProtoCrewMember.RosterStatus.Available; newKerb.experience = 0; newKerb.experienceLevel = 0; if (KBulki > 0) // Bulk hires get random stats { // The equation gives 60% of results within +/-10% of GUI setting newKerb.courage = (float)Math.Min(1, Math.Max(0, (Math.Pow(2 * rand.NextDouble() - 1, 3) / 2) + KCourage / 100)); newKerb.stupidity = (float)Math.Min(1, Math.Max(0, (Math.Pow(2 * rand.NextDouble() - 1, 3) / 2) + KStupidity / 100)); // 5% chance of Badass newKerb.isBadass = rand.NextDouble() > .95; // No chance of vets in bulk hires. newKerb.veteran = false; } else // use GUI values { newKerb.courage = KCourage / 100; newKerb.stupidity = KStupidity / 100; if (KFearless) { newKerb.isBadass = true; } if (KVeteran) { newKerb.veteran = true; } } // Hire.Log.Info("PSH :: Status set to Available, courage and stupidity set, fearless trait set."); if (kerExp == false) { newKerb.experience = 9999; newKerb.experienceLevel = 5; Hire.Log.Info("KSI :: Level set to 5 - Kerbal Experince disabled."); } else { switch (KLevel) { case 1: newKerb.flightLog.AddEntry("Training1," + FlightGlobals.GetHomeBodyName()); newKerb.ArchiveFlightLog(); newKerb.experience = 2; newKerb.experienceLevel = 1; // Hire.Log.Info("KSI :: Level set to 1."); break; case 2: newKerb.flightLog.AddEntry("Training2," + FlightGlobals.GetHomeBodyName()); newKerb.ArchiveFlightLog(); newKerb.experience = 8; newKerb.experienceLevel = 2; // Hire.Log.Info("KSI :: Level set to 2."); break; case 3: newKerb.flightLog.AddEntry("Training3," + FlightGlobals.GetHomeBodyName()); newKerb.ArchiveFlightLog(); newKerb.experience = 16; newKerb.experienceLevel = 3; // Hire.Log.Info("KSI :: Level set to 3."); break; case 4: newKerb.flightLog.AddEntry("Training4," + FlightGlobals.GetHomeBodyName()); newKerb.ArchiveFlightLog(); newKerb.experience = 32; newKerb.experienceLevel = 4; // Hire.Log.Info("KSI :: Level set to 4."); break; case 5: newKerb.flightLog.AddEntry("Training5," + FlightGlobals.GetHomeBodyName()); newKerb.ArchiveFlightLog(); newKerb.experience = 64; newKerb.experienceLevel = 5; break; } } GameEvents.onKerbalAdded.Fire(newKerb); // old gameevent most likely to be used by other mods GameEvents.onKerbalAddComplete.Fire(newKerb); // new gameevent that seems relevant } // Refreshes the AC so that new kerbal shows on the available roster. Hire.Log.Info("PSH :: Hiring Function Completed."); GameEvents.onGUIAstronautComplexDespawn.Fire(); GameEvents.onGUIAstronautComplexSpawn.Fire(); }
// We'll piggyback on the base class ConnectToDepotEvent to // handle making the connection on the destination side protected sealed override void ConnectToDepot() { try { // Check for issues that would prevent deployment var deployCheckResult = CanConnectToDepot(); if (!string.IsNullOrEmpty(deployCheckResult)) { DisplayMessage(deployCheckResult); return; } var originDepot = _registry.GetDepot(OriginBody, OriginBiome); var destinationDepot = _registry.GetDepot(vessel.mainBody.name, GetVesselBiome()); if (destinationDepot.Body == originDepot.Body && destinationDepot.Biome == originDepot.Biome) { DisplayMessage(INVALID_CONNECTION_MESSAGE); return; } CalculateAndSetFields(); if (RoutePayload < MINIMUM_PAYLOAD) { DisplayMessage(INSUFFICIENT_PAYLOAD_MESSAGE); return; } if (RouteCost > 0) { // Make sure origin depot has enough TransportCredits to support the route var originTransportCredits = originDepot .GetResources() .FirstOrDefault(r => r.ResourceName == "TransportCredits"); if (originTransportCredits == null) { DisplayMessage(string.Format(INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, RouteCost)); return; } if (originTransportCredits.Available < RouteCost) { DisplayMessage(string.Format(INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, RouteCost - originTransportCredits.Available)); return; } } if (!CanConnectToDestination(originDepot, destinationDepot, RouteCost, RoutePayload, out var errorMessage)) { DisplayMessage(errorMessage); return; } _registry.CreateRoute(originDepot.Body, originDepot.Biome, destinationDepot.Body, destinationDepot.Biome, RoutePayload); if (RouteCost > 0) { originDepot.NegotiateConsumer(new Dictionary <string, int> { { "TransportCredits", RouteCost } }); } if (originDepot.Body == destinationDepot.Body) { DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, originDepot.Body)); } else { DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, $"{originDepot.Body} and {destinationDepot.Body}")); } // Add rewards var homeworld = FlightGlobals.GetHomeBodyName(); if (destinationDepot.Body == homeworld && originDepot.Body != destinationDepot.Body) { RewardsManager.AddTransportFunds(RoutePayload); } OnConnectedToDestingation(); ResetRoute(); } catch (Exception ex) { DisplayMessage(ex.Message); } }