Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistency between editor and flight behavior regarding Wolf depot creation #1570

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 26 additions & 8 deletions Source/WOLF/WOLF/Modules/WOLF_ConverterModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class WOLF_ConverterModule : WOLF_AbstractPartModule
/// Checks for issues that would prevent connecting to a depot.
/// </summary>
/// <returns>A message if there was an error, otherwise empty string.</returns>
protected string CanConnectToDepot()
protected string CanConnectToDepot(bool duringDepotCreation = false)
{
var body = vessel.mainBody.name;
var biome = GetVesselBiome();
Expand All @@ -31,7 +31,7 @@ protected string CanConnectToDepot()
}
var otherDepotModules = vessel.FindPartModulesImplementing<WOLF_DepotModule>()
.Where(p => !(p is WOLF_SurveyModule));
if (otherDepotModules.Any())
if (otherDepotModules.Any() && !duringDepotCreation)
{
return Messenger.INVALID_DEPOT_PART_ATTACHMENT_MESSAGE;
}
Expand All @@ -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);
}
}

/// <returns>A boolean indicating, if the act of connecting was successful.</returns>
private bool ConnectToDepotWorker(string deployCheckResult)
{

if (!string.IsNullOrEmpty(deployCheckResult))
{
DisplayMessage(deployCheckResult);
return;
return false;
}

// Get recipes from all attached WOLF PartModules
Expand All @@ -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();
Expand All @@ -95,7 +114,7 @@ protected override void ConnectToDepot()
missingResource.Value,
missingResource.Key));
}
return;
return false;
}

DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, body));
Expand All @@ -111,8 +130,7 @@ protected override void ConnectToDepot()
RewardsManager.AddReputation(totalCrewPoints, vessel.mainBody.isHomeWorld);
}
}

Poof.GoPoof(vessel);
return true;
}

protected override void GetLocalizedTextValues()
Expand Down
27 changes: 23 additions & 4 deletions Source/WOLF/WOLF/Modules/WOLF_DepotModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -88,6 +89,7 @@ protected void EstablishDepot(bool isSurvey)
}

bool depotAlreadyExists = _registry.TryGetDepot(body, biome, out IDepot depot);
List<WOLF_ConverterModule> otherWolfConverterModules = null;

if (isSurvey)
{
Expand All @@ -104,17 +106,20 @@ protected void EstablishDepot(bool isSurvey)
DisplayMessage(DEPOT_ALREADY_ESTABLISHED_MESSAGE);
return;
}
var otherWolfPartModules = vessel
.FindPartModulesImplementing<WOLF_AbstractPartModule>()
var otherWolfDepotModules = vessel
.FindPartModulesImplementing<WOLF_DepotModule>()
.Where(p => p != this);
var otherWolfHopperModules = vessel.FindPartModulesImplementing<WOLF_HopperModule>();
var otherWolfTerminalModules = vessel.FindPartModulesImplementing<WOLF_TerminalModule>();
var otherWolfHoppers = vessel.FindPartModulesImplementing<WOLF_HopperModule>();
if (otherWolfPartModules.Any() || otherWolfHoppers.Any())
if (otherWolfDepotModules.Any() || otherWolfHopperModules.Any() || otherWolfTerminalModules.Any())
{
DisplayMessage(Messenger.INVALID_DEPOT_PART_ATTACHMENT_MESSAGE);
return;
}
otherWolfConverterModules = vessel.FindPartModulesImplementing<WOLF_ConverterModule>();
var crew = vessel.GetVesselCrew();
if (crew != null && crew.Count > 0)
if (crew != null && crew.Count > 0 && !otherWolfConverterModules.Any())
{
DisplayMessage(CANNOT_ADD_CREW_MESSAGE);
return;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
{
Expand Down