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

Feature Request: lock subtypes behind tech nodes #239

Open
ghost opened this issue Feb 9, 2023 · 0 comments
Open

Feature Request: lock subtypes behind tech nodes #239

ghost opened this issue Feb 9, 2023 · 0 comments

Comments

@ghost
Copy link

ghost commented Feb 9, 2023

This would be a lot less work than adding part upgrades when the desired prerequisite is merely the tech being researched

Here is the draft code for your consideration, mostly copied from the existing PartUpgrade feature. It contains two additional fields and two inserts to existing methods

#region Config Fields

[NodeData]
public string techRequired;

#endregion


#region Private Fields

public bool HasTechRequired => !techRequired.IsNullOrEmpty();

#endregion


#region Setup

private void OnLoad(ConfigNode node, OperationContext context)
{

	if (HasTechRequired && !AssetBase.RnDTechTree.GetTreeTechs().Any(t => t.techID == techRequired))
	{
		SeriousWarningHandler.DisplaySeriousWarning($"Tech node does not exist: {techRequired} on: {this}");
		LogError("Tech node does not exist: " + techRequired);
		techRequired = null;
	}

}

#endregion


#region Public Methods

public bool IsUnlocked()
{
	if (!HasUpgradeRequired && !HasTechRequired) return true;
	if (HighLogic.CurrentGame.IsNull()) return true;
	if (HighLogic.CurrentGame.Mode == Game.Modes.SANDBOX) return true;
	bool isUnlocked = true;
	if (HasUpgradeRequired)
		isUnlocked = PartUpgradeManager.Handler.IsUnlocked(upgradeRequired);
	if (HasTechRequired)
		isUnlocked = isUnlocked && ResearchAndDevelopment.Instance.GetTechState(techRequired) != null;
	return isUnlocked;
}

#endregion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants