Skip to content

Commit

Permalink
Add support for disabled (but not deleted) programs and leaders. Disa…
Browse files Browse the repository at this point in the history
…ble spaceplanes program (was never meant to ship, should have been disabled like the others; this will disable it without removing it from those who have already activated it)
  • Loading branch information
NathanKell committed Jul 2, 2023
1 parent d280b90 commit e510c50
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions GameData/RP-1/Programs/Programs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ RP0_PROGRAM
RP0_PROGRAM
{
name = CrewedSpaceplaneDev
isDisabled = true
title = Crewed Spaceplane Development
description = Spaceplanes potentially offer considerable advantages over capsules as a way to send people to orbit; in particular the controlled re-entry and runway landing makes recovery much simpler and cheaper. Proponents also cite the possibility of using aerodynamic lift to perform plane changes with less propellant. NOTE: This has contracts, but they have not been tested or balanced.
requirementsPrettyText = Complete 'X-Plane Research', and the contract 'Reach Orbital Speed & Return Safely to Earth' from the Crewed Orbit program.
Expand Down
5 changes: 4 additions & 1 deletion Source/Harmony/StrategySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ internal static bool Prefix_GetStrategies(StrategySystem __instance, string depa

StrategyConfigRP0 cfg = stratR.ConfigRP0;

if (cfg == null || cfg.IsDisabled)
continue;

if (stratR.DepartmentName != department && (string.IsNullOrEmpty(cfg.DepartmentNameAlt) || cfg.DepartmentNameAlt != department))
continue;

Expand Down Expand Up @@ -72,7 +75,7 @@ internal static bool Prefix_GetStrategies(StrategySystem __instance, string depa
continue;

string name = strat.Config.Name;
if (!acceptablePrograms.Contains(name) && !completedPrograms.Contains(name) && !ProgramHandler.Instance.DisabledPrograms.Contains(name))
if (!acceptablePrograms.Contains(name) && !completedPrograms.Contains(name) && !ProgramHandler.Instance.DisabledPrograms.Contains(name) && strat is ProgramStrategy p && !p.Program.isDisabled)
list.Add(strat);
}

Expand Down
4 changes: 4 additions & 0 deletions Source/Leaders/StrategyConfigRP0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class StrategyConfigRP0 : StrategyConfig
{
public static Dictionary<string, double> ActivatedStrategies = new Dictionary<string, double>();

[Persistent]
protected bool isDisabled;
public bool IsDisabled => isDisabled;

/// <summary>
/// Some leaders (Contractors, e.g.) can appear in two departments at once. If this is set,
/// the strategy will appear in both the main department and this one.
Expand Down
6 changes: 5 additions & 1 deletion Source/Programs/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public enum Speed
[Persistent(isPersistant = false)]
public string objectivesPrettyText;

[Persistent(isPersistant = false)]
public bool isDisabled;

[Persistent(isPersistant = false)]
public double nominalDurationYears;
public double DurationYears => DurationYearsCalc(speed, nominalDurationYears);
Expand Down Expand Up @@ -153,7 +156,7 @@ public static double TotalFundingCalc(Speed spd, double funds)

public bool IsActive => !IsComplete && acceptedUT != 0;

public bool CanAccept => !IsComplete && !IsActive && AllRequirementsMet;
public bool CanAccept => !IsComplete && !IsActive && !isDisabled && AllRequirementsMet;

public bool CanComplete => !IsComplete && IsActive && objectivesCompletedUT != 0;

Expand Down Expand Up @@ -181,6 +184,7 @@ public Program(Program toCopy) : this()
requirementsPrettyText = toCopy.requirementsPrettyText;
objectivesPrettyText = toCopy.objectivesPrettyText;
nominalDurationYears = toCopy.nominalDurationYears;
isDisabled = toCopy.isDisabled;
baseFunding = toCopy.baseFunding;
fundingCurve = toCopy.fundingCurve;
repDeltaOnCompletePerYearEarly = toCopy.repDeltaOnCompletePerYearEarly;
Expand Down

0 comments on commit e510c50

Please sign in to comment.