copied from blowfishpro#239
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
copied from blowfishpro#239
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