forked from jrossignol/ContractConfigurator
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathActiveVesselRangeRequirement.cs
67 lines (55 loc) · 2.24 KB
/
ActiveVesselRangeRequirement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KSP;
using KSPAchievements;
using RemoteTech;
using ContractConfigurator;
using KSP.Localization;
namespace ContractConfigurator.RemoteTech
{
/// <summary>
/// ContractRequirement to check the range for an active vessel at the given celestial body.
/// </summary>
public class ActiveVesselRangeRequirement : ContractRequirement
{
protected double range;
public override bool LoadFromConfig(ConfigNode configNode)
{
// Load base class
bool valid = base.LoadFromConfig(configNode);
// Before loading, verify the RemoteTech version
valid &= Util.Version.VerifyRemoteTechVersion();
// Do not check on active contracts
checkOnActiveContract = configNode.HasValue("checkOnActiveContract") ? checkOnActiveContract : false;
valid &= ConfigNodeUtil.ParseValue<double>(configNode, "range", x => range = x, this);
valid &= ValidateTargetBody(configNode);
return valid;
}
public override void OnSave(ConfigNode configNode)
{
configNode.AddValue("range", range);
}
public override void OnLoad(ConfigNode configNode)
{
range = ConfigNodeUtil.ParseValue<double>(configNode, "range", 0.0);
}
public override bool RequirementMet(ConfiguredContract contract)
{
LoggingUtil.LogVerbose(this, "Checking requirement");
// Perform another validation of the target body to catch late validation issues due to expressions
if (!ValidateTargetBody())
{
return false;
}
return RemoteTechProgressTracker.Instance.ActiveRange(targetBody) > range;
}
protected override string RequirementText()
{
string body = targetBody == null ? Localizer.GetStringByTag("#cc.req.ProgressCelestialBody.genericBody") : targetBody.displayName;
return Localizer.Format(invertRequirement ? "#cc.remotetech.req.activeVesselRange.x" : "#cc.remotetech.req.activeVesselRange", body, (range / 1000.0).ToString("N0"));
}
}
}