Skip to content

Commit

Permalink
Initial KSP 1.2 work.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrossignol committed Sep 11, 2016
1 parent 9a33f0f commit 28653cb
Show file tree
Hide file tree
Showing 22 changed files with 127 additions and 122 deletions.
3 changes: 2 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Contract Configurator 1.19.1
Contract Configurator 1.20.0
- Support for KSP 1.2
- Fixed NRE when vessel's Landed At string is null (thanks SamLex).
- Check for sufficient funds when there are negative contract advances (thanks 5thHorseman).

Expand Down
2 changes: 1 addition & 1 deletion GameData/ContractConfigurator/Agencies/Explore.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

CONTRACT_DEFINITION
{
name = ExploreBody
name = ExplorationContract
displayName = Exploration
agent = Exploration
}
Expand Down
Binary file modified GameData/ContractConfigurator/ContractConfigurator.dll
Binary file not shown.
Binary file modified GameData/ContractConfigurator/KerKonConConExt.dll
Binary file not shown.
11 changes: 4 additions & 7 deletions source/CC_RemoteTech/CC_RemoteTech.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="KSPUtil">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\KSPUtil.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="RemoteTech, Version=1.6.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\RemoteTech\Plugins\RemoteTech.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\RemoteTech\Plugins\RemoteTech.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -49,7 +46,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -79,7 +76,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /y "$(TargetPath)" "$(SolutionDir)..\GameData\ContractConfigurator\"
copy /y "$(TargetPath)" "C:\Program Files (x86)\Kerbal Space Program\GameData\ContractConfigurator\"</PostBuildEvent>
copy /y "$(TargetPath)" "C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\GameData\ContractConfigurator\"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
2 changes: 0 additions & 2 deletions source/ContractConfigurator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ Global
{4082B9BC-243E-456D-A9C5-705F4428EB36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4082B9BC-243E-456D-A9C5-705F4428EB36}.Release|Any CPU.Build.0 = Release|Any CPU
{AA91A060-C3CA-4770-8B39-F053E6ADAB5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA91A060-C3CA-4770-8B39-F053E6ADAB5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA91A060-C3CA-4770-8B39-F053E6ADAB5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA91A060-C3CA-4770-8B39-F053E6ADAB5F}.Release|Any CPU.Build.0 = Release|Any CPU
{C733C176-867C-4B72-B979-1004A1A4F193}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C733C176-867C-4B72-B979-1004A1A4F193}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C733C176-867C-4B72-B979-1004A1A4F193}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
2 changes: 1 addition & 1 deletion source/ContractConfigurator/Behaviour/SpawnKerbal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static SpawnKerbal Create(ConfigNode configNode, SpawnKerbalFactory facto
{
child.AddValue("name", "RandomKerbalName(@gender)");
}
valid &= ConfigNodeUtil.ParseValue<string>(child, "name", x => { kd.kerbal.name = x; if (kd.kerbal.pcm != null) kd.kerbal.pcm.name = x; },
valid &= ConfigNodeUtil.ParseValue<string>(child, "name", x => { kd.kerbal.name = x; if (kd.kerbal.pcm != null) kd.kerbal.pcm.ChangeName(x); },
factory);
}

Expand Down
4 changes: 2 additions & 2 deletions source/ContractConfigurator/Behaviour/SpawnVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ protected bool CreateVessels()
}
if (cd.name != null)
{
crewMember.name = cd.name;
crewMember.ChangeName(cd.name);
}

// Add them to the part
Expand Down Expand Up @@ -443,7 +443,7 @@ protected bool CreateVessels()
ProtoCrewMember crewMember = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(ProtoCrewMember.KerbalType.Unowned);
if (cd.name != null)
{
crewMember.name = cd.name;
crewMember.ChangeName(cd.name);
}

crewArray[i++] = crewMember;
Expand Down
19 changes: 9 additions & 10 deletions source/ContractConfigurator/ContractConfigurator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="KSPUtil">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\KSPUtil.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -50,10 +47,10 @@
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Kerbal Space Program\KSP_Data\Managed\UnityEngine.UI.dll</HintPath>
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\KSP_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -333,9 +330,11 @@
<PostBuildEvent>copy /y "$(TargetPath)" "$(SolutionDir)..\GameData\ContractConfigurator\"

where /q pdb2mdb.exe || pdb2mdb.exe "$(TargetFileName)"
copy /Y "$(TargetPath)" "C:\Program Files (x86)\Kerbal Space Program\GameData\ContractConfigurator\"
copy /Y "$(TargetDir)$(TargetName).pdb" "C:\Program Files (x86)\Kerbal Space Program\GameData\ContractConfigurator\"
if exist "$(TargetDir)$(TargetName).dll.mdb" (copy /Y "$(TargetDir)$(TargetName).dll.mdb" "C:\Program Files (x86)\Kerbal Space Program\GameData\ContractConfigurator\")</PostBuildEvent>
copy /Y "$(TargetPath)" "C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\GameData\ContractConfigurator\"

copy /Y "$(TargetDir)$(TargetName).pdb" "C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\GameData\ContractConfigurator\"

if exist "$(TargetDir)$(TargetName).dll.mdb" (copy /Y "$(TargetDir)$(TargetName).dll.mdb" "C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program\GameData\ContractConfigurator\")</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,21 @@ private static List<Resource> ResourceList(AvailablePart p)
List<Resource> resources = new List<Resource>();
foreach (PartResource r in p.partPrefab.Resources)
{
PartResourceDefinition resource = PartResourceLibrary.Instance.resourceDefinitions.Where(prd => prd.name == r.resourceName).FirstOrDefault();
if (resource != null)
var enumerator = PartResourceLibrary.Instance.resourceDefinitions.GetEnumerator();
try
{
resources.Add(new Resource(resource));
while (enumerator.MoveNext())
{
if (enumerator.Current.name == r.resourceName)
{
resources.Add(new Resource(enumerator.Current));
break;
}
}
}
finally
{
enumerator.Dispose();
}
}
return resources;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ public override Resource ConvertFrom<U>(U value)
{
string sVal = (string)(object)value;

// Get the actual resourece
PartResourceDefinition resource = PartResourceLibrary.Instance.resourceDefinitions.Where(prd => prd.name == sVal).FirstOrDefault();
if (resource != null)
// Get the actual resource
var enumerator = PartResourceLibrary.Instance.resourceDefinitions.GetEnumerator();
try
{
return new Resource(resource);
while (enumerator.MoveNext())
{
if (enumerator.Current.name == sVal)
{
return new Resource(enumerator.Current);
}
}
}
finally
{
enumerator.Dispose();
}
throw new ArgumentException("'" + sVal + "' is not a valid resource.");
}
Expand Down Expand Up @@ -78,10 +88,20 @@ public override Resource ParseIdentifier(Token token)
}

// Get the actual resourece
PartResourceDefinition resource = PartResourceLibrary.Instance.resourceDefinitions.Where(prd => prd.name == identifier).FirstOrDefault();
if (resource != null)
var enumerator = PartResourceLibrary.Instance.resourceDefinitions.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
if (enumerator.Current.name == identifier)
{
return new Resource(enumerator.Current);
}
}
}
finally
{
return new Resource(resource);
enumerator.Dispose();
}
throw new ArgumentException("'" + identifier + "' is not a valid resource.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void GenerateKerbal()
{
_pcm = HighLogic.CurrentGame.CrewRoster.GetNewKerbal(kerbalType);
_pcm.gender = gender;
_pcm.name = name;
_pcm.ChangeName(name);
_pcm.trait = experienceTrait;
KerbalRoster.SetExperienceTrait(_pcm, experienceTrait);
}
Expand Down
14 changes: 7 additions & 7 deletions source/ContractConfigurator/MissionControlUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void Update()
}

// Setup the toggle
Text toggleAllText = toggleAllObj.GetChild("Text").GetComponent<Text>();
TMPro.TextMeshProUGUI toggleAllText = toggleAllObj.GetChild("Text").GetComponent<TMPro.TextMeshProUGUI>();
toggleAllText.text = "All";
Toggle toggleAll = toggleAllObj.GetComponent<Toggle>();
toggleAll.onValueChanged.AddListener(new UnityAction<bool>(OnClickAll));
Expand Down Expand Up @@ -996,8 +996,8 @@ protected void SetupGroupItem(GroupContainer groupContainer)
}

// Setup the available text
Text availableText = availableTextObject.GetComponent<Text>();
availableText.alignment = TextAnchor.LowerRight;
TMPro.TextMeshProUGUI availableText = availableTextObject.GetComponent<TMPro.TextMeshProUGUI>();
availableText.alignment = TMPro.TextAlignmentOptions.BottomRight;
availableText.text = "<color=#" + (groupContainer.availableContracts == 0 ? "CCCCCC" : "8BED8B") + ">Offered: " + groupContainer.availableContracts + "</color>";
availableText.fontSize = groupContainer.mcListItem.title.fontSize - 3;

Expand Down Expand Up @@ -1308,10 +1308,10 @@ protected void UpdateContractCounts()
int exceptionalMax = Math.Min(ContractConfigurator.ContractLimit(Contract.ContractPrestige.Exceptional), maxActive);

string output = "";
output += string.Format("<b><color=#f4ee21> \t </color><color=#DB8310>Trivial Contracts:\t\t\t\t</color></b>" + (trivialCount >= trivialMax ? "<color=#f97306>{0} [Max: {1}]</color>\n" : "{0} [Max: {1}]\n"), trivialCount, trivialMax);
output += string.Format("<b><color=#f4ee21> ★★\t </color><color=#DB8310>Significant Contracts:\t\t</color></b>" + (significantCount >= significantMax ? "<color=#f97306>{0} [Max: {1}]</color>\n" : "{0} [Max: {1}]\n"), significantCount, significantMax);
output += string.Format("<b><color=#f4ee21>★★★\t </color><color=#DB8310>Exceptional Contracts:\t</color></b>" + (exceptionalCount >= exceptionalMax ? "<color=#f97306>{0} [Max: {1}]</color>\n" : "{0} [Max: {1}]\n"), exceptionalCount, exceptionalMax);
output += string.Format("<b>\t\t\t <color=#DB8310>All Active Contracts:\t\t</color></b>" + (maxActive == int.MaxValue ? "{0}" : activeCount >= maxActive ? "<color=#f97306>{0} [Max: {1}]</color>" : "{0} [Max: {1}]"), activeCount, maxActive);
output += string.Format("<b><color=#f4ee21> <sprite=0 tint=1>\t </color><color=#DB8310>Trivial Contracts:\t\t</color></b>" + (trivialCount >= trivialMax ? "<color=#f97306>{0} [Max: {1}]</color>\n" : "{0} [Max: {1}]\n"), trivialCount, trivialMax);
output += string.Format("<b><color=#f4ee21> <sprite=0 tint=1><sprite=0 tint=1>\t </color><color=#DB8310>Significant Contracts:\t</color></b>" + (significantCount >= significantMax ? "<color=#f97306>{0} [Max: {1}]</color>\n" : "{0} [Max: {1}]\n"), significantCount, significantMax);
output += string.Format("<b><color=#f4ee21><sprite=0 tint=1><sprite=0 tint=1><sprite=0 tint=1>\t </color><color=#DB8310>Exceptional Contracts:\t</color></b>" + (exceptionalCount >= exceptionalMax ? "<color=#f97306>{0} [Max: {1}]</color>\n" : "{0} [Max: {1}]\n"), exceptionalCount, exceptionalMax);
output += string.Format("<b>\t <color=#DB8310>All Active Contracts:\t\t</color></b>" + (maxActive == int.MaxValue ? "{0}" : activeCount >= maxActive ? "<color=#f97306>{0} [Max: {1}]</color>" : "{0} [Max: {1}]"), activeCount, maxActive);
MissionControl.Instance.textMCStats.text = output;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ protected override bool VesselMeetsCondition(Vessel vessel)

protected string TraitTitle(string traitName)
{
ExperienceTraitConfig config = KerbalRoster.ExperienceConfig.Categories.Where(c => c.Name == traitName).FirstOrDefault();
ExperienceTraitConfig config = GameDatabase.Instance.ExperienceConfigs.Categories.Where(c => c.Name == traitName).FirstOrDefault();

return config != null ? config.Title : traitName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected void CreateDelegates()
// Filter by part module types
foreach (string partModuleType in filter.partModuleTypes)
{
AddParameter(new CountParameterDelegate<Part>(filter.minCount, filter.maxCount, p => PartHasModuleType(p, partModuleType),
AddParameter(new CountParameterDelegate<Part>(filter.minCount, filter.maxCount, p => PartHasObjective(p, partModuleType),
"with module type: " + partModuleType, false));
}
}
Expand All @@ -123,7 +123,7 @@ protected void CreateDelegates()
// Filter by part modules
foreach (string partModuleType in filter.partModuleTypes)
{
AddParameter(new ParameterDelegate<Part>(filter.type.Prefix() + "module type: " + partModuleType, p => PartHasModuleType(p, partModuleType), filter.type));
AddParameter(new ParameterDelegate<Part>(filter.type.Prefix() + "module type: " + partModuleType, p => PartHasObjective(p, partModuleType), filter.type));
}

// Filter by part modules - extended mode
Expand Down Expand Up @@ -198,18 +198,9 @@ private bool PartHasModule(Part p, string partModule)
return false;
}

private bool PartHasModuleType(Part p, string partModuleType)
private bool PartHasObjective(Part p, string contractObjective)
{
List<string> modules = ContractDefs.GetModules(partModuleType);

foreach (PartModule pm in p.Modules)
{
if (modules.Contains(pm.moduleName))
{
return true;
}
}
return false;
return p.HasValidContractObjective(contractObjective);
}

private bool PartModuleCheck(Part p, ConfigNode.Value v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override bool Load(ConfigNode configNode)
PartValidation.Filter filter = new PartValidation.Filter(defaultMatch);
valid &= ConfigNodeUtil.ParseValue<List<AvailablePart>>(configNode, "part", x => filter.parts = x, this, new List<AvailablePart>());
valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "partModule", x => filter.partModules = x, this, new List<string>(), x => x.All(Validation.ValidatePartModule));
valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "partModuleType", x => filter.partModuleTypes = x, this, new List<string>(), x => x.All(Validation.ValidatePartModuleType));
valid &= ConfigNodeUtil.ParseValue<List<string>>(configNode, "partModuleType", x => filter.partModuleTypes = x, this, new List<string>());
valid &= ConfigNodeUtil.ParseValue<PartCategories?>(configNode, "category", x => filter.category = x, this, (PartCategories?)null);
valid &= ConfigNodeUtil.ParseValue<string>(configNode, "manufacturer", x => filter.manufacturer = x, this, (string)null);
filters.Add(filter);
Expand Down Expand Up @@ -83,7 +83,7 @@ public override bool Load(ConfigNode configNode)
PartValidation.Filter filter = new PartValidation.Filter(matchType);
valid &= ConfigNodeUtil.ParseValue<List<AvailablePart>>(child, "part", x => filter.parts = x, this, new List<AvailablePart>());
valid &= ConfigNodeUtil.ParseValue<List<string>>(child, "partModule", x => filter.partModules = x, this, new List<string>(), x => x.All(Validation.ValidatePartModule));
valid &= ConfigNodeUtil.ParseValue<List<string>>(child, "partModuleType", x => filter.partModuleTypes = x, this, new List<string>(), x => x.All(Validation.ValidatePartModuleType));
valid &= ConfigNodeUtil.ParseValue<List<string>>(child, "partModuleType", x => filter.partModuleTypes = x, this, new List<string>());
valid &= ConfigNodeUtil.ParseValue<PartCategories?>(child, "category", x => filter.category = x, this, (PartCategories?)null);
valid &= ConfigNodeUtil.ParseValue<string>(child, "manufacturer", x => filter.manufacturer = x, this, (string)null);

Expand Down
Loading

0 comments on commit 28653cb

Please sign in to comment.