From 943032cd4cfb9534bc6d9c2e746cfa3c5be57417 Mon Sep 17 00:00:00 2001 From: Mhoram Kerbin Date: Sat, 27 Aug 2022 19:40:39 +0200 Subject: [PATCH] Allow Converters to be attached to the same vessel as a Depot --- .../WOLF/Localization/en-us.cfg | 1 + .../WOLF/WOLF/Modules/WOLF_ConverterModule.cs | 34 ++++++++++++++----- Source/WOLF/WOLF/Modules/WOLF_DepotModule.cs | 27 ++++++++++++--- 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/Localization/en-us.cfg b/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/Localization/en-us.cfg index e6cccc678..121b40a02 100644 --- a/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/Localization/en-us.cfg +++ b/FOR_RELEASE/GameData/UmbraSpaceIndustries/WOLF/Localization/en-us.cfg @@ -67,6 +67,7 @@ Localization #autoLOC_USI_WOLF_ESTABLISH_DEPOT_GUI_NAME = Establish depot #autoLOC_USI_WOLF_NO_DEPOTS_ESTABLISHED_MESSAGE = There are currently no established depots. #autoLOC_USI_WOLF_SURVEY_GUI_NAME = Survey WOLF Biome + #autoLOC_USI_WOLF_CONVERTERS_ABANDONED_DURING_DEPOT_CREATION_MESSAGE = Converter Modules abandoned during depot creation. // Converter messages #autoLOC_USI_WOLF_NEEDS = Needs diff --git a/Source/WOLF/WOLF/Modules/WOLF_ConverterModule.cs b/Source/WOLF/WOLF/Modules/WOLF_ConverterModule.cs index 139fa156e..b1b393e4d 100644 --- a/Source/WOLF/WOLF/Modules/WOLF_ConverterModule.cs +++ b/Source/WOLF/WOLF/Modules/WOLF_ConverterModule.cs @@ -12,7 +12,7 @@ public class WOLF_ConverterModule : WOLF_AbstractPartModule /// Checks for issues that would prevent connecting to a depot. /// /// A message if there was an error, otherwise empty string. - protected string CanConnectToDepot() + protected string CanConnectToDepot(bool duringDepotCreation = false) { var body = vessel.mainBody.name; var biome = GetVesselBiome(); @@ -31,7 +31,7 @@ protected string CanConnectToDepot() } var otherDepotModules = vessel.FindPartModulesImplementing() .Where(p => !(p is WOLF_SurveyModule)); - if (otherDepotModules.Any()) + if (otherDepotModules.Any() && !duringDepotCreation) { return Messenger.INVALID_DEPOT_PART_ATTACHMENT_MESSAGE; } @@ -44,14 +44,33 @@ protected string CanConnectToDepot() return string.Empty; } + public bool ConnectToDepotDirectlyAfterDepotCreation() + { + var deployCheckResult = CanConnectToDepot(true); + var success = ConnectToDepotWorker(deployCheckResult); + return success; + } + protected override void ConnectToDepot() { // Check for issues that would prevent deployment var deployCheckResult = CanConnectToDepot(); + var success = ConnectToDepotWorker(deployCheckResult); + + if (success) + { + Poof.GoPoof(vessel); + } + } + + /// A boolean indicating, if the act of connecting was successful. + private bool ConnectToDepotWorker(string deployCheckResult) + { + if (!string.IsNullOrEmpty(deployCheckResult)) { DisplayMessage(deployCheckResult); - return; + return false; } // Get recipes from all attached WOLF PartModules @@ -68,12 +87,12 @@ protected override void ConnectToDepot() if (crewModule == null) { DisplayMessage("BUG: Could not find crew module."); - return; + return false; } else if (!crewModule.IsCrewEligible()) { DisplayMessage(CREW_NOT_ELIGIBLE_MESSAGE); - return; + return false; } var crewRecipe = crewModule.GetCrewRecipe(); @@ -95,7 +114,7 @@ protected override void ConnectToDepot() missingResource.Value, missingResource.Key)); } - return; + return false; } DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, body)); @@ -111,8 +130,7 @@ protected override void ConnectToDepot() RewardsManager.AddReputation(totalCrewPoints, vessel.mainBody.isHomeWorld); } } - - Poof.GoPoof(vessel); + return true; } protected override void GetLocalizedTextValues() diff --git a/Source/WOLF/WOLF/Modules/WOLF_DepotModule.cs b/Source/WOLF/WOLF/Modules/WOLF_DepotModule.cs index 9fc27823f..0022a0e5d 100644 --- a/Source/WOLF/WOLF/Modules/WOLF_DepotModule.cs +++ b/Source/WOLF/WOLF/Modules/WOLF_DepotModule.cs @@ -16,6 +16,7 @@ public class WOLF_DepotModule : WOLF_AbstractPartModule private static string SUCCESSFUL_DEPLOYMENT_MESSAGE = "#autoLOC_USI_WOLF_DEPOT_SUCCESSFUL_DEPLOYMENT_MESSAGE"; // "Your depot has been established at {0} on {1}!"; private static string SUCCESSFUL_SURVEY_MESSAGE = "#autoLOC_USI_WOLF_DEPOT_SUCCESSFUL_SURVEY_MESSAGE"; // "Survey completed at {0} on {1}!"; private static string SURVEY_ALREADY_COMPLETED_MESSAGE = "#autoLOC_USI_WOLF_DEPOT_SURVEY_ALREADY_COMPLETE_MESSAGE"; // "A survey has already been completed in this biome!"; + private static string CONVERTERS_ABANDONED_DURING_DEPOT_CREATION_MESSAGE = "#autoLOC_USI_WOLF_CONVERTERS_ABANDONED_DURING_DEPOT_CREATION_MESSAGE"; // "Converter Modules abandoned during depot creation."; private static readonly HarvestTypes[] DEFAULT_HARVEST_TYPES = new HarvestTypes[] { HarvestTypes.Atmospheric, HarvestTypes.Planetary }; private static readonly HarvestTypes[] OCEANIC_HARVEST_TYPES = new HarvestTypes[] { HarvestTypes.Atmospheric, HarvestTypes.Oceanic, HarvestTypes.Planetary }; @@ -88,6 +89,7 @@ protected void EstablishDepot(bool isSurvey) } bool depotAlreadyExists = _registry.TryGetDepot(body, biome, out IDepot depot); + List otherWolfConverterModules = null; if (isSurvey) { @@ -104,17 +106,20 @@ protected void EstablishDepot(bool isSurvey) DisplayMessage(DEPOT_ALREADY_ESTABLISHED_MESSAGE); return; } - var otherWolfPartModules = vessel - .FindPartModulesImplementing() + var otherWolfDepotModules = vessel + .FindPartModulesImplementing() .Where(p => p != this); + var otherWolfHopperModules = vessel.FindPartModulesImplementing(); + var otherWolfTerminalModules = vessel.FindPartModulesImplementing(); var otherWolfHoppers = vessel.FindPartModulesImplementing(); - if (otherWolfPartModules.Any() || otherWolfHoppers.Any()) + if (otherWolfDepotModules.Any() || otherWolfHopperModules.Any() || otherWolfTerminalModules.Any()) { DisplayMessage(Messenger.INVALID_DEPOT_PART_ATTACHMENT_MESSAGE); return; } + otherWolfConverterModules = vessel.FindPartModulesImplementing(); var crew = vessel.GetVesselCrew(); - if (crew != null && crew.Count > 0) + if (crew != null && crew.Count > 0 && !otherWolfConverterModules.Any()) { DisplayMessage(CANNOT_ADD_CREW_MESSAGE); return; @@ -160,6 +165,16 @@ protected void EstablishDepot(bool isSurvey) depot.NegotiateConsumer(WolfRecipe.InputIngredients); DisplayMessage(string.Format(SUCCESSFUL_DEPLOYMENT_MESSAGE, biome, body)); + + if (otherWolfConverterModules.Any()) + { + WOLF_ConverterModule converterModule = otherWolfConverterModules.First(); + var success = converterModule.ConnectToDepotDirectlyAfterDepotCreation(); + if (!success) + { + DisplayMessage(CONVERTERS_ABANDONED_DURING_DEPOT_CREATION_MESSAGE); + } + } Poof.GoPoof(vessel); // Add rewards @@ -206,6 +221,10 @@ public override void OnStart(StartState state) { SURVEY_ALREADY_COMPLETED_MESSAGE = surveyCompletedMessage; } + if (Localizer.TryGetStringByTag("#CONVERTERS_ABANDONED_DURING_DEPOT_CREATION_MESSAGE", out string convertersAbandonedMessage)) + { + CONVERTERS_ABANDONED_DURING_DEPOT_CREATION_MESSAGE = convertersAbandonedMessage; + } if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_ESTABLISH_DEPOT_GUI_NAME", out string establishGuiName)) {