-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- v3.19.0.0
- v3.18.0.0
- v3.17.0.0
- v3.16.0.0
- v3.15.0.0
- v3.14.0.0
- v3.13.0.0
- v3.12.0.0
- v3.11.0.0
- v3.10.0.0
- v3.9.0.0
- v3.8.0.0
- v3.7.0.0
- v3.6.1.0
- v3.6.0.0
- v3.5.0.0
- v3.4.0.0
- v3.3.0.1
- v3.3.0.0
- v3.2.1.0
- v3.2.0.1
- v3.2.0.0
- v3.1.1.2
- v3.1.1.1
- v3.1.1.0
- v3.0.0.2
- v3.0.0.1
- v3.0.0.0
- v2.13.0.0
- v2.12.0.0
- v2.11.0.1
- v2.11.0.0
- v2.10.0.0
- v2.9.1.1
- v2.9.1.0
- v2.9.0.1
- v2.9.0.0
- v2.8.1.0
- v2.8.0.0
- v2.7.1.0
- v2.7.0.0
- v2.6.4.0
- v2.6.3.0
- v2.6.2.0
- v2.6.1.1
- v2.6.0.0
- v2.5.0.0
- v2.4.2.0
- v2.4.1.0
- v2.4.0.0
- v2.3.0.0
- v2.2.0.0
- v2.1.0.0
- v2.0.2.0
- v2.0.1.0
- v2.0.0.0
- v1.13.2.2
- v1.13.2.1
- v1.13.2.0
- v1.13.1.0
- v1.13.0.0
- v1.12.19.0
- v1.12.18.0
- v1.12.17.0
- v1.12.16.0
- v1.12.15.0
- v1.12.14.0
- v1.12.13.0
- v1.12.12.0
- v1.12.11.0
- v1.12.10.0
- v1.12.9.0
- v1.12.8.0
- v1.12.7.0
- v1.12.6.0
- v1.12.5.0
- v1.12.4.0
- v1.12.3.0
- v1.12.2.0
- v1.12.1.0
- v1.12.0.0
- v1.11.11.0
- v1.11.10.0
- v1.11.9.0
- v1.11.8.0
- v1.11.7.0
- v1.11.6.0
- v1.11.5.0
- v1.11.4.0
- v1.11.3.0
- v1.11.2.0
- v1.11.1.0
- v1.11.0.0
- v1.10.7.0
- v1.10.6.1
- v1.10.6.0
- v1.10.5.0
- v1.10.4.0
- v1.10.3.0
- v1.10.2.0
- v1.10.0.1
- v1.10.0.0
- v1.9.1
- v1.9.0
- v1.8.1
- v1.8
- v1.7
- v1.6
- v1.5
- v1.4.1
- v1.3
- v1.2.1
- v1.2
- v1.1.1
- v1.1
- v1.00
- 3.1.0.0
- 3.0.1.0
- 1.4
1 parent
507f483
commit 6cfdc96
Showing
7 changed files
with
502 additions
and
8 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using KSP; | ||
using UnityEngine; | ||
|
||
namespace RP0 | ||
{ | ||
class ModuleToolingPTank : ModuleTooling | ||
{ | ||
protected PartModule procTank, procShape; | ||
protected string shapeName = string.Empty; | ||
protected bool cone = false; | ||
|
||
protected BaseField diam1, diam2, length; | ||
|
||
public override void OnAwake() | ||
{ | ||
base.OnAwake(); | ||
|
||
procTank = part.Modules["ProceduralPart"]; | ||
} | ||
protected void GetDimensions(out float diam, out float len) | ||
{ | ||
diam = 0f; | ||
len = 0f; | ||
|
||
if (procTank == null) | ||
return; | ||
|
||
string newName = procTank.Fields["shapeName"].GetValue<string>(procTank); | ||
if (newName != shapeName || procShape == null) | ||
{ | ||
shapeName = newName; | ||
switch (shapeName) | ||
{ | ||
case "Smooth Cone": | ||
procShape = part.Modules["ProceduralShapeBezierCone"]; | ||
cone = true; | ||
break; | ||
case "Cone": | ||
procShape = part.Modules["ProceduralShapeCone"]; | ||
cone = true; | ||
break; | ||
case "Fillet Cylinder": | ||
procShape = part.Modules["ProceduralShapePill"]; | ||
break; | ||
|
||
default: // "Cylinder" | ||
procShape = part.Modules["ProceduralShapeCylinder"]; | ||
break; | ||
} | ||
|
||
if (procShape == null) | ||
return; | ||
|
||
if (cone) | ||
{ | ||
diam1 = procShape.Fields["topDiameter"]; | ||
diam2 = procShape.Fields["bottomDiameter"]; | ||
} | ||
else | ||
{ | ||
diam1 = procShape.Fields["Diameter"]; | ||
diam2 = null; | ||
} | ||
|
||
length = procShape.Fields["length"]; | ||
} | ||
else if (procShape == null) | ||
return; | ||
|
||
if (cone) | ||
diam = Math.Max(diam1.GetValue<float>(procShape), diam2.GetValue<float>(procShape)); | ||
else | ||
diam = diam1.GetValue<float>(procShape); | ||
|
||
len = length.GetValue<float>(procShape); | ||
} | ||
|
||
public override float GetToolingCost() | ||
{ | ||
float d, l; | ||
GetDimensions(out d, out l); | ||
float cost = lengthToolingCost.x * d * d + lengthToolingCost.y * d + lengthToolingCost.z * l + lengthToolingCost.w; | ||
if (ToolingDatabase.HasTooling(toolingType, d, l) == ToolingDatabase.ToolingLevel.None) | ||
cost += diameterToolingCost.x * d * d + diameterToolingCost.y * d + diameterToolingCost.z; | ||
|
||
return cost; | ||
} | ||
|
||
public override void PurchaseTooling() | ||
{ | ||
float d, l; | ||
GetDimensions(out d, out l); | ||
ToolingDatabase.UnlockTooling(toolingType, d, l); | ||
} | ||
|
||
public override bool IsUnlocked() | ||
{ | ||
float d, l; | ||
GetDimensions(out d, out l); | ||
return ToolingDatabase.HasTooling(toolingType, d, l) == ToolingDatabase.ToolingLevel.Full; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using KSP; | ||
using UnityEngine; | ||
|
||
namespace RP0 | ||
{ | ||
public abstract class ModuleTooling : PartModule, IPartCostModifier | ||
{ | ||
[KSPField] | ||
public string toolingType = "TankStarting"; | ||
|
||
[KSPField] | ||
public string toolingName = "Tool Tank"; | ||
|
||
[KSPField] | ||
public float untooledMultiplier = 10f; | ||
|
||
[KSPField] | ||
public float finalToolingCostMultiplier = 1f; | ||
|
||
[KSPField] | ||
// d^2, d^1, 1 | ||
public Vector3 diameterToolingCost = new Vector3(6000f, 12000f, 500f); | ||
|
||
[KSPField] | ||
// d^2, d^1, l^1, 1 | ||
public Vector4 lengthToolingCost = new Vector4(500f, 2000f, 200f, 100f); | ||
|
||
[KSPEvent(guiActive = false, guiActiveEditor = true, guiName = "Tool Tank")] | ||
public virtual void ToolingEvent() | ||
{ | ||
if (IsUnlocked()) | ||
return; | ||
|
||
float toolingCost = GetToolingCost(); | ||
bool canAfford = true; | ||
if (!HighLogic.CurrentGame.Parameters.Difficulty.BypassEntryPurchaseAfterResearch) | ||
{ | ||
if (Funding.Instance.Funds < toolingCost) | ||
canAfford = false; | ||
} | ||
else | ||
toolingCost = 0f; | ||
|
||
PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), | ||
new Vector2(0.5f, 0.5f), | ||
new MultiOptionDialog( | ||
"Tooling has not yet been set up for this part. It will cost " + toolingCost.ToString("N0") + " funds.", | ||
"ModuleManager", | ||
HighLogic.UISkin, | ||
new Rect(0.5f, 0.5f, 150f, 60f), | ||
new DialogGUIFlexibleSpace(), | ||
new DialogGUIVerticalLayout( | ||
new DialogGUIFlexibleSpace(), | ||
new DialogGUIButton(canAfford ? "Purchase Tooling" : "Can't Afford", | ||
() => | ||
{ | ||
if (canAfford) | ||
{ | ||
Funding.Instance.AddFunds(-toolingCost, TransactionReasons.RnDPartPurchase); | ||
PurchaseTooling(); | ||
Events["ToolingEvent"].guiActiveEditor = false; | ||
} | ||
}, 140.0f, 30.0f, true), | ||
new DialogGUIButton("Close", () => { }, 140.0f, 30.0f, true) | ||
)), | ||
false, | ||
HighLogic.UISkin); | ||
} | ||
|
||
public abstract float GetToolingCost(); | ||
|
||
public abstract void PurchaseTooling(); | ||
|
||
public abstract bool IsUnlocked(); | ||
|
||
public override void OnLoad(ConfigNode node) | ||
{ | ||
base.OnLoad(node); | ||
|
||
Events["ToolingEvent"].guiActiveEditor = IsUnlocked(); | ||
Events["ToolingEvent"].guiName = toolingName; | ||
} | ||
|
||
public virtual float GetModuleCost(float defaultCost, ModifierStagingSituation sit) | ||
{ | ||
if (IsUnlocked()) | ||
return 0f; | ||
|
||
float cost = part.partInfo.cost; | ||
float baseCost = cost; | ||
|
||
for (int i = part.Modules.Count; i-- > 0;) | ||
{ | ||
PartModule m = part.Modules[i]; | ||
if (m is ModuleTooling) | ||
continue; | ||
|
||
IPartCostModifier c = m as IPartCostModifier; | ||
if (c == null) | ||
continue; | ||
|
||
cost += c.GetModuleCost(baseCost, ModifierStagingSituation.CURRENT); | ||
} | ||
|
||
return cost; | ||
} | ||
|
||
public ModifierChangeWhen GetModuleCostChangeWhen() | ||
{ | ||
return ModifierChangeWhen.FIXED; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using KSP; | ||
using UnityEngine; | ||
|
||
namespace RP0 | ||
{ | ||
public struct ToolingDiameter | ||
{ | ||
public double diameter; | ||
|
||
public List<double> lengths; | ||
|
||
public ToolingDiameter(double d) | ||
{ | ||
diameter = d; | ||
lengths = new List<double>(); | ||
} | ||
|
||
public ToolingDiameter(double d, double l) | ||
{ | ||
diameter = d; | ||
lengths = new List<double>(); | ||
lengths.Add(l); | ||
} | ||
} | ||
public class ToolingDatabase | ||
{ | ||
protected static double comparisonEpsilonHigh = 1.04d; | ||
protected static double comparisonEpsilonLow = 0.96d; | ||
|
||
protected static int EpsilonCompare(double a, double b) | ||
{ | ||
if (a > b * comparisonEpsilonLow && a < b * comparisonEpsilonHigh) | ||
return 0; | ||
|
||
return a.CompareTo(b); | ||
} | ||
|
||
protected static Dictionary<string, List<ToolingDiameter>> toolings = new Dictionary<string, List<ToolingDiameter>>(); | ||
|
||
protected static int DiamIndex(double diam, List<ToolingDiameter> lst, out int min) | ||
{ | ||
min = 0; | ||
int max = lst.Count - 1; | ||
do | ||
{ | ||
int mid = (min + max) / 2; | ||
switch (EpsilonCompare(diam, lst[mid].diameter)) | ||
{ | ||
case 0: | ||
return mid; | ||
|
||
case 1: | ||
min = mid + 1; | ||
break; | ||
|
||
default: | ||
case -1: | ||
max = mid - 1; | ||
break; | ||
} | ||
} | ||
while (min <= max); | ||
return -1; | ||
} | ||
|
||
protected static int LengthIndex(double length, List<double> lst, out int min) | ||
{ | ||
min = 0; | ||
int max = lst.Count - 1; | ||
do | ||
{ | ||
int mid = (min + max) / 2; | ||
switch (EpsilonCompare(length, lst[mid])) | ||
{ | ||
case 0: | ||
return mid; | ||
|
||
case 1: | ||
min = mid + 1; | ||
break; | ||
|
||
default: | ||
case -1: | ||
max = mid - 1; | ||
break; | ||
} | ||
} | ||
while (min <= max); | ||
return -1; | ||
} | ||
|
||
public enum ToolingLevel | ||
{ | ||
None = 0, | ||
Diameter = 1, | ||
Full = 2 | ||
}; | ||
|
||
public static ToolingLevel HasTooling(string type, double diam, double len) | ||
{ | ||
List<ToolingDiameter> lst; | ||
if (toolings.TryGetValue(type, out lst)) | ||
{ | ||
int tmp; | ||
int dIndex = DiamIndex(diam, lst, out tmp); | ||
if (dIndex == -1) | ||
return ToolingLevel.None; | ||
|
||
int lIndex = LengthIndex(len, lst[dIndex].lengths, out tmp); | ||
|
||
return lIndex == -1 ? ToolingLevel.Diameter : ToolingLevel.Full; | ||
} | ||
|
||
return ToolingLevel.None; | ||
} | ||
|
||
public static bool UnlockTooling(string type, double diam, double len) | ||
{ | ||
List<ToolingDiameter> lst; | ||
if (toolings.TryGetValue(type, out lst)) | ||
{ | ||
int insertionIdx; | ||
int dIndex = DiamIndex(diam, lst, out insertionIdx); | ||
if (dIndex == -1) | ||
{ | ||
ToolingDiameter d = new ToolingDiameter(diam, len); | ||
lst.Insert(insertionIdx, d); | ||
return true; | ||
} | ||
|
||
int lIndex = LengthIndex(len, lst[dIndex].lengths, out insertionIdx); | ||
|
||
if (lIndex != -1) | ||
{ | ||
return false; | ||
} | ||
else | ||
{ | ||
ToolingDiameter d = lst[dIndex]; | ||
d.lengths.Insert(insertionIdx, len); | ||
lst[dIndex] = d; | ||
return true; | ||
} | ||
} | ||
else | ||
return false; | ||
} | ||
|
||
|
||
public static void Load(ConfigNode node) | ||
{ | ||
toolings.Clear(); | ||
foreach (ConfigNode c in node.GetNodes("TYPE")) | ||
{ | ||
string type = c.GetValue("type"); | ||
if (string.IsNullOrEmpty(type)) | ||
continue; | ||
|
||
List<ToolingDiameter> lst = new List<ToolingDiameter>(); | ||
|
||
foreach (ConfigNode n in c.GetNodes("DIAMETER")) | ||
{ | ||
double tmp = 0d; | ||
if (!n.TryGetValue("diameter", ref tmp)) | ||
continue; | ||
|
||
ToolingDiameter d = new ToolingDiameter(tmp); | ||
|
||
ConfigNode len = n.GetNode("LENGTHS"); | ||
if (len != null) | ||
foreach (ConfigNode.Value v in len.values) | ||
if (double.TryParse(v.value, out tmp)) | ||
d.lengths.Add(tmp); | ||
|
||
lst.Add(d); | ||
} | ||
|
||
toolings[type] = lst; | ||
} | ||
} | ||
|
||
public static void Save(ConfigNode node) | ||
{ | ||
foreach (KeyValuePair<string, List<ToolingDiameter>> kvp in toolings) | ||
{ | ||
ConfigNode c = node.AddNode("TYPE"); | ||
c.AddValue("type", kvp.Key); | ||
|
||
foreach (ToolingDiameter d in kvp.Value) | ||
{ | ||
ConfigNode n = c.AddNode("DIAMETER"); | ||
n.AddValue("diameter", d.diameter.ToString("G17")); | ||
|
||
ConfigNode len = n.AddNode("LENGTHS"); | ||
for (int i = 0, iC = d.lengths.Count; i < iC; ++i) | ||
len.AddValue("length", d.lengths[i].ToString("G17")); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using KSP; | ||
using UnityEngine; | ||
|
||
namespace RP0 | ||
{ | ||
[KSPScenario(ScenarioCreationOptions.AddToAllGames, new GameScenes[] { GameScenes.EDITOR, GameScenes.SPACECENTER })] | ||
public class ToolingManager : ScenarioModule | ||
{ | ||
#region Fields | ||
|
||
protected static ToolingDatabase database = new ToolingDatabase(); | ||
|
||
#region Instance | ||
|
||
private static ToolingManager _instance = null; | ||
public static ToolingManager Instance | ||
{ | ||
get | ||
{ | ||
return _instance; | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#endregion | ||
|
||
#region Overrides and Monobehaviour methods | ||
|
||
public override void OnAwake() | ||
{ | ||
base.OnAwake(); | ||
|
||
if (_instance != null) | ||
{ | ||
GameObject.Destroy(_instance); | ||
} | ||
_instance = this; | ||
} | ||
|
||
public override void OnLoad(ConfigNode node) | ||
{ | ||
base.OnLoad(node); | ||
|
||
ToolingDatabase.Load(node.GetNode("Tooling")); | ||
|
||
} | ||
public override void OnSave(ConfigNode node) | ||
{ | ||
base.OnSave(node); | ||
|
||
ToolingDatabase.Save(node.AddNode("Tooling")); | ||
} | ||
|
||
#endregion | ||
} | ||
} |