Skip to content

Commit

Permalink
Showing 9 changed files with 389 additions and 1 deletion.
Binary file modified GameData/RP-0/Plugins/RP0.dll
Binary file not shown.
Binary file added GameData/RP-0/Plugins/RP0KCTBinder.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/Crew/CrewHandler.cs
Original file line number Diff line number Diff line change
@@ -153,7 +153,7 @@ public void Update()
{
toRemove.Add(kvp.Key);
retirees.Add(kvp.Key);
pcm.rosterStatus = ProtoCrewMember.RosterStatus.Missing;
pcm.rosterStatus = ProtoCrewMember.RosterStatus.Dead;


PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
57 changes: 57 additions & 0 deletions Source/KCTBinderModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using KerbalConstructionTime;

namespace RP0
{
[KSPScenario(ScenarioCreationOptions.AddToAllGames, new GameScenes[] { GameScenes.EDITOR, GameScenes.FLIGHT, GameScenes.SPACECENTER, GameScenes.TRACKSTATION })]
public class KCTBinderModule : ScenarioModule
{
// FIXME if we change the min build rate, FIX THIS.
protected const double BuildRateOffset = -0.05001d;

protected double nextTime = -1d;
protected double checkInterval = 0.5d;
protected int[] padCounts = new int[10];
protected void Update()
{
if (HighLogic.CurrentGame == null)
return;

if (KerbalConstructionTime.KerbalConstructionTime.instance == null)
return;

if (MaintenanceHandler.Instance == null)
return;

double time = Planetarium.GetUniversalTime();
if (nextTime > time)
return;

nextTime = time + checkInterval;

double buildRate = 0d;
for (int i = padCounts.Length; i-- > 0;)
padCounts[i] = 0;

foreach (KCT_KSC ksc in KCT_GameStates.KSCs)
{

for (int i = ksc.VABRates.Count; i-- > 0;)
buildRate += Math.Max(0d, ksc.VABRates[i] + BuildRateOffset);
for (int i = ksc.SPHRates.Count; i-- > 0;)
buildRate += Math.Max(0d, ksc.SPHRates[i] + BuildRateOffset);
for (int i = ksc.LaunchPads.Count; i-- > 0;)
++padCounts[ksc.LaunchPads[i].level];
}
double RDRate = KCT_MathParsing.ParseNodeRateFormula(10, 0, false);

MaintenanceHandler.Instance.kctBuildRate = buildRate;
MaintenanceHandler.Instance.kctResearcRate = RDRate;
MaintenanceHandler.Instance.kctPadCounts = padCounts;
}
}
}
182 changes: 182 additions & 0 deletions Source/Maintenance/MaintenanceHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KSP;
using UnityEngine;
using System.Reflection;

namespace RP0
{
[KSPScenario(ScenarioCreationOptions.AddToAllGames, new GameScenes[] { GameScenes.EDITOR, GameScenes.FLIGHT, GameScenes.SPACECENTER, GameScenes.TRACKSTATION })]
public class MaintenanceHandler : ScenarioModule
{
#region Fields

protected double nextUpdate = -1d;
protected double lastUpdate = 0d;
protected double updateInterval = 3600d;
protected bool wasWarpingHigh = false;

public double kctBuildRate = 0;
public double kctResearcRate = 0;
public int[] kctPadCounts = new int[10];

protected double facilityLevelCostMult = 0.00001d;
protected double kctBPMult = 1000000d;
protected double kctResearchMult = 50000000d / 86400d;
protected double nautYearlyUpkeepAdd = 5000d;
protected double nautYearlyUpkeepBase = 500d;

protected Dictionary<SpaceCenterFacility, Upgradeables.UpgradeableFacility.UpgradeLevel[]> facilityLevels = new Dictionary<SpaceCenterFacility, Upgradeables.UpgradeableFacility.UpgradeLevel[]>();

#region Instance

private static MaintenanceHandler _instance = null;
public static MaintenanceHandler Instance
{
get
{
return _instance;
}
}

#endregion

#endregion

#region Overrides and Monobehaviour methods

public override void OnAwake()
{

if (_instance != null)
{
GameObject.Destroy(_instance);
}
_instance = this;
}

public void Update()
{
if (HighLogic.CurrentGame == null)
return;

if (facilityLevels.Count == 0)
{
foreach (Upgradeables.UpgradeableFacility facility in GameObject.FindObjectsOfType<Upgradeables.UpgradeableFacility>())
{
facilityLevels[(SpaceCenterFacility)Enum.Parse(typeof(SpaceCenterFacility), facility.name)] = facility.UpgradeLevels;
}
}

double time = Planetarium.GetUniversalTime();
if (nextUpdate > time)
{
if (wasWarpingHigh && TimeWarp.CurrentRate <= 100f)
wasWarpingHigh = false;
else
return;
}

Upgradeables.UpgradeableFacility.UpgradeLevel[] levels;
double facilityUpkeep = 0d;

// Pad
if (facilityLevels.TryGetValue(SpaceCenterFacility.LaunchPad, out levels))
{
if (kctResearcRate > 0d)
{
int lC = levels.Length - 1;
for (int i = kctPadCounts.Length; i-- > 0;)
{
if (i > lC)
continue;

facilityUpkeep += facilityLevelCostMult * levels[i].levelCost;
}
}
else
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.LaunchPad) * (levels.Length + 0.05f))].levelCost;
}

// Runway
if (facilityLevels.TryGetValue(SpaceCenterFacility.Runway, out levels))
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.Runway) * (levels.Length + 0.05f))].levelCost;

//VAB
if (facilityLevels.TryGetValue(SpaceCenterFacility.VehicleAssemblyBuilding, out levels))
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding) * (levels.Length + 0.05f))].levelCost;

//SPH
if (facilityLevels.TryGetValue(SpaceCenterFacility.SpaceplaneHangar, out levels))
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar) * (levels.Length + 0.05f))].levelCost;

//RnD
if (facilityLevels.TryGetValue(SpaceCenterFacility.ResearchAndDevelopment, out levels))
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.ResearchAndDevelopment) * (levels.Length + 0.05f))].levelCost;

// MC
if (facilityLevels.TryGetValue(SpaceCenterFacility.MissionControl, out levels))
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.MissionControl) * (levels.Length + 0.05f))].levelCost;

// TS
if (facilityLevels.TryGetValue(SpaceCenterFacility.TrackingStation, out levels))
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.TrackingStation) * (levels.Length + 0.05f))].levelCost;

// AC
if (facilityLevels.TryGetValue(SpaceCenterFacility.AstronautComplex, out levels))
facilityUpkeep += facilityLevelCostMult * levels[(int)(ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.AstronautComplex) * (levels.Length + 0.05f))].levelCost;


double nautUpkeep = HighLogic.CurrentGame.CrewRoster.GetActiveCrewCount()
* (nautYearlyUpkeepBase
+ ((double)ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.AstronautComplex)
* nautYearlyUpkeepAdd))
* (1d / (86400d * 365d));

double kctBPUpkeep = kctBuildRate * kctBPMult;
double kctRDUpkeep = kctResearcRate * kctResearchMult;

double totalUpkeep = facilityUpkeep + kctBPUpkeep + kctRDUpkeep + nautUpkeep;

double timePassed = time - lastUpdate;

Funding.Instance.AddFunds(-timePassed * (totalUpkeep * (1d / 86400d)), TransactionReasons.StructureRepair);

lastUpdate = time;

if (TimeWarp.CurrentRate <= 100f)
{
wasWarpingHigh = false;
if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
{
PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
new Vector2(0.5f, 0.5f),
"Maintenance",
"We are paying the following maintenance costs per day/year:\nFacilities: "
+ facilityUpkeep.ToString("N0") + "/" + (facilityUpkeep * 365d).ToString("N0")
+ "\nIntegration / Pad Support Teams: " + (kctBPUpkeep).ToString("N0") + "/" + (kctBPUpkeep*365d).ToString("N0")
+ "\nResarch Teams:" + (kctRDUpkeep).ToString("N0") + "/" + (kctRDUpkeep* 365d).ToString("N0")
+ "\nAstronauts:" + (nautUpkeep).ToString("N0") + "/" + (nautUpkeep* 365d).ToString("N0"),
"OK",
true,
HighLogic.UISkin);
}
nextUpdate = time + updateInterval;
}
else
{
wasWarpingHigh = true;
nextUpdate = time + updateInterval * (TimeWarp.CurrentRate * (1f / 100f));
}
}

public void OnDestroy()
{

}

#endregion
}
}
36 changes: 36 additions & 0 deletions Source/Properties/AssemblyInfoKCT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("RP0KCTBinder")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RP0KCTBinder")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("13cd17e5-381c-4782-b5f0-3da46513eeb8")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
1 change: 1 addition & 0 deletions Source/RP0.csproj
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Compile Include="Maintenance\MaintenanceHandler.cs" />
<Compile Include="Crew\CrewHandler.cs" />
<Compile Include="LoadingScreenChanger.cs" />
<Compile Include="DifficultyPresets.cs" />
14 changes: 14 additions & 0 deletions Source/RP0.sln
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RP0", "RP0.csproj", "{997854F8-4EFB-4A78-87BC-F7C8CEA64669}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RP0KCTBinder", "RP0KCTBinder.csproj", "{13CD17E5-381C-4782-B5F0-3DA46513EEB8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -27,6 +29,18 @@ Global
{997854F8-4EFB-4A78-87BC-F7C8CEA64669}.Release|x64.Build.0 = Release|Any CPU
{997854F8-4EFB-4A78-87BC-F7C8CEA64669}.Release|x86.ActiveCfg = Release|Any CPU
{997854F8-4EFB-4A78-87BC-F7C8CEA64669}.Release|x86.Build.0 = Release|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Debug|x64.ActiveCfg = Debug|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Debug|x64.Build.0 = Debug|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Debug|x86.ActiveCfg = Debug|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Debug|x86.Build.0 = Debug|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Release|Any CPU.Build.0 = Release|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Release|x64.ActiveCfg = Release|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Release|x64.Build.0 = Release|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Release|x86.ActiveCfg = Release|Any CPU
{13CD17E5-381C-4782-B5F0-3DA46513EEB8}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
98 changes: 98 additions & 0 deletions Source/RP0KCTBinder.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{13CD17E5-381C-4782-B5F0-3DA46513EEB8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RP0KCTBinder</RootNamespace>
<AssemblyName>RP0KCTBinder</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\GameData\RP-0\Plugins\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Compile Include="KCTBinderModule.cs" />
<Compile Include="Properties\AssemblyInfoKCT.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\..\..\Games\Steam\steamapps\common\Kerbal Space Program\KSP_x64_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="KerbalConstructionTime">
<HintPath>..\..\..\..\..\..\Games\RO_122\GameData\KerbalConstructionTime\plugins\KerbalConstructionTime.dll</HintPath>
</Reference>
<Reference Include="System">
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\..\..\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>..\..\..\Managed\UnityEngine.UI.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="RP0.csproj">
<Project>{997854f8-4efb-4a78-87bc-f7c8cea64669}</Project>
<Name>RP0</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>del "System.Core.dll"</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.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

0 comments on commit ecf9403

Please sign in to comment.