forked from FractalUK/KSPInterstellar
-
Notifications
You must be signed in to change notification settings - Fork 13
/
FNAmatCatFissionFusionReactor.cs
149 lines (129 loc) · 8.8 KB
/
FNAmatCatFissionFusionReactor.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//extern alias ORSv1_1;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using OpenResourceSystem;
namespace InterstellarPlugin {
[KSPModule("Antimatter Initiated Reactor")]
class FNAmatCatFissionFusionReactor : FNReactor {
protected double ticker = 0;
protected double stored_tick = 0;
protected GameObject lightGameObject;
protected Light light;
protected PartResource deuterium;
protected PartResource he3;
protected PartResource un;
protected double antimatter_rate = 0;
protected double un_rate = 0;
protected double d_he3_rate = 0;
protected double upgraded_d_he3_rate = 0;
protected double upgraded_amat_rate = 0;
public override void OnStart(PartModule.StartState state) {
deuterium = part.Resources["Deuterium"];
he3 = part.Resources["Helium-3"];
un = part.Resources["EnrichedUranium"];
base.OnStart(state);
/*
lightGameObject = GameObject.CreatePrimitive(PrimitiveType.Sphere);
lightGameObject.collider.enabled = false;
lightGameObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
lightGameObject.AddComponent<Light>();
lightGameObject.renderer.material.shader = Shader.Find("Unlit/Transparent");
lightGameObject.renderer.material.mainTexture = GameDatabase.Instance.GetTexture("Interstellar/explode2", false);
lightGameObject.renderer.material.color = new Color(Color.white.r, Color.white.g, Color.white.b, 0.9f);
lightGameObject.renderer.enabled = false;
light = lightGameObject.light;
lightGameObject.transform.position = part.transform.position;
light.type = LightType.Point;
light.color = new Color(Color.white.r, Color.white.g, 0.87f, 1f);
light.range = 1f;
light.intensity = 50.0f;
light.renderMode = LightRenderMode.ForcePixel;
convert_charged_to_thermal = false;
Destroy (lightGameObject.collider, 0.25f);
Destroy(lightGameObject, 0.1f);
*/
antimatter_rate = resourceRate * GameConstants.antimatter_initiated_antimatter_cons_constant*86400/1000000;
d_he3_rate = resourceRate * GameConstants.antimatter_initiated_d_he3_cons_constant*86400;
un_rate = resourceRate * GameConstants.antimatter_initiated_eu_cons_constant*86400;
upgraded_d_he3_rate = upgradedResourceRate * GameConstants.antimatter_initiated_upgraded_eu_cons_constant;
upgraded_amat_rate = upgradedResourceRate * GameConstants.antimatter_initiated_antimatter_cons_constant * 86400 / 1000000;
}
/*
public override void OnUpdate() {
base.OnUpdate();
if (IsEnabled && total_power_ratio > 0) {
if (lightGameObject != null & light != null) {
lightGameObject.transform.position = part.transform.position;
light.range = 0;
double flash_rate = Math.Max(charged_power_ratio, minimumThrottle);
if (ticker >= stored_tick + 0.15 / flash_rate) {
stored_tick = Planetarium.GetUniversalTime();
lightGameObject.transform.localScale = new Vector3(0.01f, 0.01f, 0.01f);
lightGameObject.renderer.enabled = true;
} else if (ticker >= stored_tick + 0.1) {
lightGameObject.renderer.enabled = false;
} else {
float stage = (float)((ticker - stored_tick) * 10f);
lightGameObject.transform.localScale = new Vector3(stage, stage, stage);
light.range = stage * 4;
}
}
} else {
if (lightGameObject != null & light != null) {
lightGameObject.renderer.enabled = false;
}
}
if (vessel.altitude < PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) {
Events["ActivateReactor"].active = false;
statusStr = "Offline: In Atmosphere.";
}
ticker = Planetarium.GetUniversalTime();
}
public override void OnFixedUpdate() {
base.OnFixedUpdate();
if (vessel.altitude < PluginHelper.getMaxAtmosphericAltitude(vessel.mainBody)) {
IsEnabled = false;
}
}*/
public override float getMinimumThermalPower() {
return getThermalPower() * minimumThrottle;
}
public override string GetInfo() {
float antimatter_rate = resourceRate * (float)GameConstants.antimatter_initiated_antimatter_cons_constant * 86400 * 1000000;
float d_he3_rate = resourceRate * (float)GameConstants.antimatter_initiated_d_he3_cons_constant * 86400;
float un_rate = resourceRate * (float)GameConstants.antimatter_initiated_eu_cons_constant * 86400;
float upgraded_d_he3_rate = upgradedResourceRate * (float)GameConstants.antimatter_initiated_upgraded_d_he3_cons_constant * 86400;
float upgraded_amat_rate = upgradedResourceRate * (float)GameConstants.antimatter_initiated_antimatter_cons_constant * 86400 * 1000000;
return String.Format("[Base Part Information]\nPart Name: {0}\nCore Temperature: {1:n0}K\nTotal Power Output: {2:n0}MW\nD/He-3 Consumption Rate (Max): {3}Kg/day\nUN Consumption Rate (Max): {4}m^3 /day\nAntimatter Consumption Rate (Max): {5}ng/day\n\n[Upgrade Information]\nScience Tech Required:\n- Antimatter Power\nPartName: {6}\nCore Temperature: {7:n0}K\nTotal Power Output: {8:n0}MW\nD/He-3 Consumption Rate (Max): {9}Kg/day\nUNConsumption Rate (Max): {10}m^3 /day\nAntimatter Consumption Rate (Max): {11}ng/day", originalName, ReactorTemp, ThermalPower, d_he3_rate, un_rate, antimatter_rate, upgradedName, upgradedReactorTemp, upgradedThermalPower, upgraded_d_he3_rate, un_rate, upgraded_amat_rate);
}
protected override double consumeReactorResource(double resource) {
double deuterium_he3_consumption = isupgraded ? resource * GameConstants.antimatter_initiated_upgraded_d_he3_cons_constant : resource * GameConstants.antimatter_initiated_d_he3_cons_constant;
double un_consumption = isupgraded ? resource * GameConstants.antimatter_initiated_upgraded_eu_cons_constant : resource * GameConstants.antimatter_initiated_eu_cons_constant;
double antimatter_consumption = GameConstants.antimatter_initiated_antimatter_cons_constant * resource;
double delta_deut = deuterium.amount - Math.Max(0, deuterium.amount - deuterium_he3_consumption);
double delta_he3 = he3.amount - Math.Max(0, he3.amount - deuterium_he3_consumption);
double delta_un = un.amount - Math.Max(0, un.amount - un_consumption);
double delta_amat = ORSHelper.fixedRequestResource(part, "Antimatter", antimatter_consumption);
deuterium.amount = Math.Max(0, deuterium.amount - deuterium_he3_consumption);
he3.amount = Math.Max(0, he3.amount - deuterium_he3_consumption);
un.amount = Math.Max(0, un.amount - un_consumption);
return resource * Math.Min(delta_deut / deuterium_he3_consumption, Math.Min(delta_he3 / deuterium_he3_consumption, Math.Min(delta_un / un_consumption,delta_amat / antimatter_consumption)));
}
protected override double returnReactorResource(double resource) {
double deuterium_he3_consumption = isupgraded ? resource * GameConstants.antimatter_initiated_upgraded_d_he3_cons_constant : resource * GameConstants.antimatter_initiated_d_he3_cons_constant;
double un_consumption = isupgraded ? resource * GameConstants.antimatter_initiated_upgraded_eu_cons_constant : resource * GameConstants.antimatter_initiated_eu_cons_constant;
double antimatter_consumption = GameConstants.antimatter_initiated_antimatter_cons_constant * resource;
double delta_deut = Math.Min(deuterium.maxAmount, deuterium.amount + deuterium_he3_consumption) - deuterium.amount;
double delta_he3 = Math.Min(he3.maxAmount, he3.amount + deuterium_he3_consumption) - he3.amount;
double delta_un = Math.Min(un.maxAmount, un.amount + un_consumption) - un.amount;
double delta_amat = -ORSHelper.fixedRequestResource(part, "Antimatter", -antimatter_consumption);
deuterium.amount = Math.Min(deuterium.maxAmount, deuterium.amount + deuterium_he3_consumption);
he3.amount = Math.Min(he3.maxAmount, he3.amount + deuterium_he3_consumption);
un.amount = Math.Min(un.maxAmount, un.amount + un_consumption);
return resource;
}
}
}