-
Notifications
You must be signed in to change notification settings - Fork 7
/
CustomGameVariables.cs
1146 lines (952 loc) · 49.1 KB
/
CustomGameVariables.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using UniLinq;
using System.Text;
using CommNet;
using UnityEngine;
namespace CustomBarnKit
{
public class CustomGameVariables : GameVariables
{
// Those values are present in GameVariables but I did
// not add anything to change them yet
//public AnimationCurve reputationAddition;
//public AnimationCurve reputationSubtraction;
//public float mentalityFundsTrivial = 1.1f;
//public float mentalityFundsSignificant = 1.2f;
//public float mentalityFundsExceptional = 1.3f;
//public float mentalityReputationTrivial = 1.1f;
//public float mentalityReputationSignificant = 1.2f;
//public float mentalityReputationExceptional = 1.3f;
//public float mentalityScienceTrivial = 1.1f;
//public float mentalityScienceSignificant = 1.2f;
//public float mentalityScienceExceptional = 1.3f;
//public float mentalityExpiryTrivial = 1.1f;
//public float mentalityExpirySignificant = 1.2f;
//public float mentalityExpiryExceptional = 1.3f;
//public float mentalityDeadlineTrivial = 1.1f;
//public float mentalityDeadlineSignificant = 1.2f;
//public float mentalityDeadlineExceptional = 1.3f;
public GameVariables original;
// Editor
public int levelsLaunchPad = 3;
public int levelsRunway = 3;
public int levelsVAB = 3;
public int levelsSPH = 3;
public float[] upgradesVAB;
public float[] upgradesSPH;
public float[] upgradesLaunchPad;
public float[] upgradesRunway;
public int[] upgradesVisualVAB;
public int[] upgradesVisualSPH;
public int[] upgradesVisualLaunchPad;
public int[] upgradesVisualRunway;
private float actionGroupsCustomUnlockVAB = 0.6f;
private float actionGroupsCustomUnlockSPH = 0.6f;
private float actionGroupsStockUnlockVAB = 0.4f;
private float actionGroupsStockUnlockSPH = 0.4f;
private float[] craftMassLimitLaunchPad;
private float[] craftMassLimitRunway;
private Vector3[] craftSizeLimitLaunchPad;
private Vector3[] craftSizeLimitRunway;
private int[] partCountLimitVAB;
private int[] partCountLimitSPH;
public bool useBuildingLaunchPad = false;
public bool useBuildingRunway = false;
// Astronauts Complex
public int levelsAstronauts = 3;
public float[] upgradesAstronauts;
public int[] upgradesVisualAstronauts;
private float recruitHireBaseCost = 10000f;
private float recruitHireFlatRate = 1.25f;
private float recruitHireRateModifier = 0.015f;
private float unlockedEVA = 0.2f;
private float unlockedEVAClamber = 0.6f;
private float unlockedEVAFlags = 0.4f;
private bool EVAChuteOnBuilding = false;
private float unlockedEVAChute = 3;
private bool homebodyAtmoEVA = false;
private bool homebodyEVA = true;
private int[] activeCrewLimit;
private float[] crewLevelLimit;
private bool recruitHireFixedRate = false;
// Mission control
public int levelsMission = 3;
public float[] upgradesMission;
public int[] upgradesVisualMission;
private float unlockedFlightPlanning = 0.4f;
private int[] activeContractsLimit;
// Not used for now
private Dictionary<string, float[]> scoreSituationCustom = new Dictionary<string, float[]>();
private float[] scoreSituationHome;
private float[] scoreSituationOther;
//public float partRecoveryValueFactor = 0.9f;
//public float resourceRecoveryValueFactor = 0.95f;
//public float reputationKerbalDeath = 10f;
//public float reputationKerbalRecovery = 25f;
//public float contractPrestigeTrivial = 1f;
//public float contractPrestigeSignificant = 1.25f;
//public float contractPrestigeExceptional = 1.5f;
//public float contractDestinationWeight = 1f;
//public float contractFundsAdvanceFactor = 1f;
//public float contractFundsCompletionFactor = 1f;
//public float contractFundsFailureFactor = 1f;
//public float contractReputationCompletionFactor = 1f;
//public float contractReputationFailureFactor = 1f;
//public float contractScienceCompletionFactor = 1f;
// Tracking Station
public int levelsTracking = 3;
public float[] upgradesTracking;
public int[] upgradesVisualTracking;
private float unlockedSpaceObjectDiscovery = 0.6f;
private int[] orbitDisplayMode;
private int[] patchesAheadLimit;
private int[] trackedObjectLimit;
private double[] DSNRange;
private DoubleCurve DSNRangeCurve;
private DoubleCurve DSNPowerCurve;
private DoubleCurve DSNScienceCurve;
// Administration
public int levelsAdministration = 3;
public float[] upgradesAdministration;
public int[] upgradesVisualAdministration;
private int[] activeStrategyLimit;
private float[] strategyCommitRange;
// R&D
public int levelsRnD = 3;
public float[] upgradesRnD;
public int[] upgradesVisualRnD;
private float[] dataToScienceRatio;
private float[] scienceCostLimit;
private float unlockedFuelTransfer = 0.2f;
private static bool debug = false;
// ReSharper disable once Unity.RedundantEventFunction
private void Awake()
{
// just here to avoid a call to the stock one
}
public void Load(GameVariables orig)
{
CustomBarnKit.log("Loading new career/science config");
#if DEBUG
debug = true;
#endif
original = orig;
// Init our values with the one from the default config
reputationAddition = orig.reputationAddition;
reputationSubtraction = orig.reputationSubtraction;
ConfigNode[] configs = GameDatabase.Instance.GetConfigNodes("CUSTOMBARNKIT");
if (configs == null || configs.Length == 0)
{
CustomBarnKit.log("No config to load");
return;
}
if (configs.Length > 1)
{
CustomBarnKit.log("More than 1 CustomBarnKit node found. Loading the first one");
}
ConfigNode config = configs[0];
ConfigNode node = new ConfigNode();
if (config.TryGetNode("VAB", ref node))
{
LoadValue(node, "levels", ref levelsVAB);
LoadValue(node, "upgrades", ref upgradesVAB);
LoadValue(node, "upgradesVisual", ref upgradesVisualVAB);
LoadValue(node, "actionGroupsCustomUnlock", ref actionGroupsCustomUnlockVAB);
LoadValue(node, "actionGroupsStockUnlock", ref actionGroupsStockUnlockVAB);
LoadValue(node, "partCountLimit", ref partCountLimitVAB);
}
if (config.TryGetNode("SPH", ref node))
{
LoadValue(node, "levels", ref levelsSPH);
LoadValue(node, "upgrades", ref upgradesSPH);
LoadValue(node, "upgradesVisual", ref upgradesVisualSPH);
LoadValue(node, "actionGroupsCustomUnlock", ref actionGroupsCustomUnlockSPH);
LoadValue(node, "actionGroupsStockUnlock", ref actionGroupsStockUnlockSPH);
LoadValue(node, "partCountLimit", ref partCountLimitSPH);
}
if (config.TryGetNode("LAUNCHPAD", ref node))
{
LoadValue(node, "levels", ref levelsLaunchPad);
LoadValue(node, "upgrades", ref upgradesLaunchPad);
LoadValue(node, "upgradesVisual", ref upgradesVisualLaunchPad);
LoadValue(node, "craftMassLimit", ref craftMassLimitLaunchPad);
LoadValue(node, "craftSizeLimit", ref craftSizeLimitLaunchPad);
LoadValue(node, "useBuilding", ref useBuildingLaunchPad);
}
if (config.TryGetNode("RUNWAY", ref node))
{
LoadValue(node, "levels", ref levelsRunway);
LoadValue(node, "upgrades", ref upgradesRunway);
LoadValue(node, "upgradesVisual", ref upgradesVisualRunway);
LoadValue(node, "craftMassLimit", ref craftMassLimitRunway);
LoadValue(node, "craftSizeLimit", ref craftSizeLimitRunway);
LoadValue(node, "useBuilding", ref useBuildingRunway);
}
if (config.TryGetNode("ASTRONAUTS", ref node))
{
LoadValue(node, "levels", ref levelsAstronauts);
LoadValue(node, "upgrades", ref upgradesAstronauts);
LoadValue(node, "upgradesVisual", ref upgradesVisualAstronauts);
LoadValue(node, "recruitHireBaseCost", ref recruitHireBaseCost);
LoadValue(node, "recruitHireFlatRate", ref recruitHireFlatRate);
LoadValue(node, "recruitHireRateModifier", ref recruitHireRateModifier);
LoadValue(node, "recruitHireFixedRate", ref recruitHireFixedRate);
LoadValue(node, "unlockedEVA", ref unlockedEVA);
LoadValue(node, "unlockedEVAClamber", ref unlockedEVAClamber);
LoadValue(node, "unlockedEVAFlags", ref unlockedEVAFlags);
LoadValue(node, "unlockedEVAChute", ref unlockedEVAChute);
LoadValue(node, "EVAChuteOnBuilding", ref EVAChuteOnBuilding);
LoadValue(node, "homebodyAtmoEVA", ref homebodyAtmoEVA);
LoadValue(node, "homebodyEVA", ref homebodyEVA);
LoadValue(node, "activeCrewLimit", ref activeCrewLimit);
LoadValue(node, "crewLevelLimit", ref crewLevelLimit);
}
if (config.TryGetNode("MISSION", ref node))
{
LoadValue(node, "levels", ref levelsMission);
LoadValue(node, "upgrades", ref upgradesMission);
LoadValue(node, "upgradesVisual", ref upgradesVisualMission);
LoadValue(node, "unlockedFlightPlanning", ref unlockedFlightPlanning);
LoadValue(node, "activeContractsLimit", ref activeContractsLimit);
LoadValue(node, "scoreSituationHome", ref scoreSituationHome);
LoadValue(node, "scoreSituationOther", ref scoreSituationOther);
LoadValue(node, "partRecoveryValueFactor", ref partRecoveryValueFactor);
LoadValue(node, "resourceRecoveryValueFactor", ref resourceRecoveryValueFactor);
LoadValue(node, "reputationKerbalDeath", ref reputationKerbalDeath);
LoadValue(node, "reputationKerbalRecovery", ref reputationKerbalRecovery);
LoadValue(node, "contractPrestigeTrivial", ref contractPrestigeTrivial);
LoadValue(node, "contractPrestigeSignificant", ref contractPrestigeSignificant);
LoadValue(node, "contractPrestigeExceptional", ref contractPrestigeExceptional);
LoadValue(node, "contractDestinationWeight", ref contractDestinationWeight);
LoadValue(node, "contractFundsAdvanceFactor", ref contractFundsAdvanceFactor);
LoadValue(node, "contractFundsCompletionFactor", ref contractFundsCompletionFactor);
LoadValue(node, "contractFundsFailureFactor", ref contractFundsFailureFactor);
LoadValue(node, "contractReputationCompletionFactor", ref contractReputationCompletionFactor);
LoadValue(node, "contractReputationFailureFactor", ref contractReputationFailureFactor);
LoadValue(node, "contractScienceCompletionFactor", ref contractScienceCompletionFactor);
}
if (config.TryGetNode("TRACKING", ref node))
{
LoadValue(node, "levels", ref levelsTracking);
LoadValue(node, "upgrades", ref upgradesTracking);
LoadValue(node, "upgradesVisual", ref upgradesVisualTracking);
LoadValue(node, "unlockedSpaceObjectDiscovery", ref unlockedSpaceObjectDiscovery);
// Import 1.1.18 and older orbitDisplayMode single value config
float odm = 0;
if (node.HasValue("orbitDisplayMode") && node.TryGetValue("orbitDisplayMode", ref odm))
{
orbitDisplayMode = new int[levelsTracking];
for (int i = 0; i < levelsTracking; i++)
{
orbitDisplayMode[i] = i < odm - 1 ? 2 : 3;
}
}
else
{
LoadValue(node, "orbitDisplayMode", ref orbitDisplayMode);
}
LoadValue(node, "patchesAheadLimit", ref patchesAheadLimit);
LoadValue(node, "trackedObjectLimit", ref trackedObjectLimit);
LoadValue(node, "DSNRange", ref DSNRange);
LoadValue(node, "DSNRangeCurve", ref DSNRangeCurve);
LoadValue(node, "DSNPowerCurve", ref DSNPowerCurve);
LoadValue(node, "DSNScienceCurve", ref DSNScienceCurve);
}
if (config.TryGetNode("ADMINISTRATION", ref node))
{
LoadValue(node, "levels", ref levelsAdministration);
LoadValue(node, "upgrades", ref upgradesAdministration);
LoadValue(node, "upgradesVisual", ref upgradesVisualAdministration);
LoadValue(node, "activeStrategyLimit", ref activeStrategyLimit);
LoadValue(node, "strategyCommitRange", ref strategyCommitRange);
}
if (config.TryGetNode("RESEARCH", ref node))
{
LoadValue(node, "levels", ref levelsRnD);
LoadValue(node, "upgrades", ref upgradesRnD);
LoadValue(node, "upgradesVisual", ref upgradesVisualRnD);
LoadValue(node, "dataToScienceRatio", ref dataToScienceRatio);
LoadValue(node, "scienceCostLimit", ref scienceCostLimit);
LoadValue(node, "unlockedFuelTransfer", ref unlockedFuelTransfer);
}
}
public override int GetActiveContractsLimit(float mCtrlNormLevel)
{
if (activeContractsLimit == null || activeContractsLimit.Length != levelsMission)
{
debugLog("activeContractsLimit wrong size");
return original.GetActiveContractsLimit(mCtrlNormLevel);
}
return NormLevelToArrayValue(mCtrlNormLevel, activeContractsLimit);
}
public override int GetActiveCrewLimit(float astroComplexNormLevel)
{
if (activeCrewLimit == null || activeCrewLimit.Length != levelsAstronauts)
{
debugLog("activeCrewLimit wrong size");
return original.GetActiveCrewLimit(astroComplexNormLevel);
}
return NormLevelToArrayValue(astroComplexNormLevel, activeCrewLimit);
}
public override int GetActiveStrategyLimit(float adminNormLevel)
{
if (activeStrategyLimit == null || activeStrategyLimit.Length != levelsAdministration)
{
debugLog("activeStrategyLimit wrong size");
return original.GetActiveStrategyLimit(adminNormLevel);
}
return NormLevelToArrayValue(adminNormLevel, activeStrategyLimit);
}
//public override float GetContractDestinationWeight(CelestialBody body)
//public override float GetContractFundsAdvanceFactor(Contract.ContractPrestige prestige)
//public override float GetContractFundsCompletionFactor(Contract.ContractPrestige prestige)
//public override float GetContractFundsFailureFactor(Contract.ContractPrestige prestige)
//public override float GetContractLevelLimit(float mCtrlNormLevel)
//public override float GetContractPrestigeFactor(Contract.ContractPrestige prestige)
//public override float GetContractReputationCompletionFactor(Contract.ContractPrestige prestige)
//public override float GetContractReputationFailureFactor(Contract.ContractPrestige prestige)
//public override float GetContractScienceCompletionFactor(Contract.ContractPrestige prestige)
public override float GetCraftMassLimit(float editorNormLevel, bool isPad)
{
int levels = isPad ? levelsLaunchPad : levelsRunway;
if (craftMassLimitLaunchPad == null || craftMassLimitLaunchPad.Length != levels)
{
debugLog("craftMassLimitRunway wrong size");
return original.GetCraftMassLimit(editorNormLevel, isPad);
}
return NormLevelToArrayValue(editorNormLevel, isPad ? craftMassLimitLaunchPad : craftMassLimitRunway);
}
public override Vector3 GetCraftSizeLimit(float editorNormLevel, bool isPad)
{
int levels = isPad
? (useBuildingLaunchPad ? levelsVAB : levelsLaunchPad)
: (useBuildingRunway ? levelsSPH : levelsRunway);
if (isPad && useBuildingLaunchPad)
editorNormLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding);
if (!isPad && useBuildingRunway)
editorNormLevel = ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar);
if (isPad && (craftSizeLimitLaunchPad == null || craftSizeLimitLaunchPad.Length != levels))
{
debugLog("craftSizeLimitLaunchPad wrong size");
return original.GetCraftSizeLimit(editorNormLevel, true);
}
if (!isPad && (craftSizeLimitRunway == null || craftSizeLimitRunway.Length != levels))
{
debugLog("craftSizeLimitRunway wrong size");
return original.GetCraftSizeLimit(editorNormLevel, false);
}
return NormLevelToArrayValue(editorNormLevel, isPad ? craftSizeLimitLaunchPad : craftSizeLimitRunway);
}
public override float GetCrewLevelLimit(float astroComplexNormLevel)
{
if (crewLevelLimit == null || crewLevelLimit.Length != levelsAstronauts)
{
debugLog("crewLevelLimit wrong size");
return original.GetCrewLevelLimit(astroComplexNormLevel);
}
return NormLevelToArrayValue(astroComplexNormLevel, crewLevelLimit);
}
public override float GetDataToScienceRatio(float RnDnormLevel)
{
if (dataToScienceRatio == null || dataToScienceRatio.Length != levelsRnD)
{
debugLog("dataToScienceRatio wrong size");
return original.GetDataToScienceRatio(RnDnormLevel);
}
return NormLevelToArrayValue(RnDnormLevel, dataToScienceRatio);
}
//public override string GetEVALockedReason(Vessel v, ProtoCrewMember crew)
//public override float GetExperimentLevel(float RnDnormLevel)
//public override float GetMentalityDeadlineFactor(float mentalityFactor, Contract.ContractPrestige prestige)
//public override float GetMentalityExpiryFactor(float mentalityFactor, Contract.ContractPrestige prestige)
//public override float GetMentalityFundsFactor(float mentalityFactor, Contract.ContractPrestige prestige)
//public override float GetMentalityReputationFactor(float mentalityFactor, Contract.ContractPrestige prestige)
//public override float GetMentalityScienceFactor(float mentalityFactor, Contract.ContractPrestige prestige)
public override int GetPartCountLimit(float editorNormLevel, bool isVAB)
{
int levels = isVAB ? levelsVAB : levelsSPH;
if (partCountLimitVAB == null || partCountLimitVAB.Length != levels)
{
debugLog("partCountLimitVAB wrong size");
return original.GetPartCountLimit(editorNormLevel, isVAB);
}
return NormLevelToArrayValue(editorNormLevel, isVAB ? partCountLimitVAB : partCountLimitSPH);
}
public override int GetPatchesAheadLimit(float tsNormLevel)
{
if (patchesAheadLimit == null || patchesAheadLimit.Length != levelsTracking)
{
debugLog("patchesAheadLimit wrong size");
return original.GetPatchesAheadLimit(tsNormLevel);
}
return NormLevelToArrayValue(tsNormLevel, patchesAheadLimit);
}
//public override float GetRecoveredPartValue(float pValue)
//public override float GetRecoveredResourceValue(float rscValue)
//public static float GetRecruitHireCost(int currentActive, float baseCost, float flatRate, float rateModifier)
public override float GetRecruitHireCost(int currentActive)
{
return recruitHireFixedRate
? recruitHireBaseCost
: GameVariables.GetRecruitHireCost(currentActive, recruitHireBaseCost, recruitHireFlatRate,
recruitHireRateModifier);
}
public override float GetScienceCostLimit(float RnDnormLevel)
{
if (scienceCostLimit == null || scienceCostLimit.Length != levelsRnD)
{
debugLog("scienceCostLimit wrong size");
return original.GetScienceCostLimit(RnDnormLevel);
}
return NormLevelToArrayValue(RnDnormLevel, scienceCostLimit);
}
public override float GetStrategyCommitRange(float adminNormLevel)
{
if (strategyCommitRange == null || strategyCommitRange.Length != levelsAdministration)
{
debugLog("strategyCommitRange wrong size");
return original.GetStrategyCommitRange(adminNormLevel);
}
return NormLevelToArrayValue(adminNormLevel, strategyCommitRange);
}
//public override float GetStrategyLevelLimit(float adminNormLevel)
public override int GetTrackedObjectLimit(float tsNormLevel)
{
if (trackedObjectLimit == null || trackedObjectLimit.Length != levelsTracking)
{
debugLog("trackedObjectLimit wrong size");
return original.GetTrackedObjectLimit(tsNormLevel);
}
return NormLevelToArrayValue(tsNormLevel, trackedObjectLimit);
}
public override double GetDSNRange(float level)
{
if (DSNRange == null || DSNRange.Length != levelsTracking)
{
debugLog("DSNRange wrong size");
return original.GetDSNRange(level);
}
return NormLevelToArrayValue(level, DSNRange) * (HighLogic.CurrentGame == null ? 1 : HighLogic.CurrentGame.Parameters.CustomParams<CommNetParams>().DSNModifier);
}
public override DoubleCurve GetDSNRangeCurve()
{
return DSNRangeCurve;
}
public override DoubleCurve GetDSNPowerCurve()
{
return DSNPowerCurve;
}
public override DoubleCurve GetDSNScienceCurve()
{
return DSNScienceCurve;
}
// public override UntrackedObjectClass MinTrackedObjectSize(float tsNormLevel)
//public override float ScoreFlightEnvelope(float altitude, float altEnvelope, float speed, float speedEnvelope)
public override float ScoreSituation(Vessel.Situations sit, CelestialBody where)
{
if (scoreSituationHome == null || scoreSituationHome.Length != 8 ||
scoreSituationOther == null || scoreSituationOther.Length != 8)
{
debugLog("scoreSituationHome wrong size");
return original.ScoreSituation(sit, where);
}
float[] scoreSituation;
if (where == Planetarium.fetch.Home)
{
scoreSituation = scoreSituationHome;
}
else if (scoreSituationCustom.ContainsKey(where.bodyName)) // bodyName can have space ?
{
scoreSituation = scoreSituationCustom[where.bodyName];
if (scoreSituation.Length != 8)
{
scoreSituation = scoreSituationOther;
}
}
else
{
scoreSituation = scoreSituationOther;
}
switch (sit)
{
case Vessel.Situations.PRELAUNCH:
return scoreSituation[0];
case Vessel.Situations.LANDED:
return scoreSituation[1];
case Vessel.Situations.SPLASHED:
return scoreSituation[2];
case Vessel.Situations.FLYING:
return scoreSituation[3];
case Vessel.Situations.SUB_ORBITAL:
return scoreSituation[4];
case Vessel.Situations.ORBITING:
return scoreSituation[5];
case Vessel.Situations.ESCAPING:
return scoreSituation[6];
case Vessel.Situations.DOCKED:
return scoreSituation[7];
default:
return scoreSituation[7];
}
}
public override bool UnlockedActionGroupsCustom(float editorNormLevel, bool isVAB)
{
int levels = isVAB ? levelsVAB : levelsSPH;
return HighLogic.CurrentGame != null &&
HighLogic.CurrentGame.Parameters.CustomParams<GameParameters.AdvancedParams>().ActionGroupsAlways ||
editorNormLevel > ((isVAB ? actionGroupsCustomUnlockVAB : actionGroupsCustomUnlockSPH) - 1.1) / (levels - 1);
}
public override bool UnlockedActionGroupsStock(float editorNormLevel, bool isVAB)
{
int levels = isVAB ? levelsVAB : levelsSPH;
return HighLogic.CurrentGame != null &&
HighLogic.CurrentGame.Parameters.CustomParams<GameParameters.AdvancedParams>().ActionGroupsAlways ||
editorNormLevel > ((isVAB ? actionGroupsStockUnlockVAB : actionGroupsStockUnlockSPH) - 1.1) / (levels - 1);
}
public override bool UnlockedEVA(float astroComplexNormLevel)
{
return astroComplexNormLevel > (unlockedEVA - 1.1) / (levelsAstronauts - 1);
}
public override bool UnlockedEVAClamber(float astroComplexNormLevel)
{
return astroComplexNormLevel > (unlockedEVAClamber - 1.1) / (levelsAstronauts - 1);
}
public override bool UnlockedEVAFlags(float astroComplexNormLevel)
{
return astroComplexNormLevel >= (unlockedEVAFlags - 1.1) / (levelsAstronauts - 1);
}
public override bool EVAIsPossible(bool evaUnlocked, Vessel v)
{
if (evaUnlocked)
return true;
return homebodyEVA && v.mainBody == Planetarium.fetch.Home && (homebodyAtmoEVA || v.LandedOrSplashed);
}
public static bool CanCrewMemberUseParachute(ProtoCrewMember crewMember)
{
if (crewMember == null)
return false;
if (CustomBarnKit.customGameVariables.EVAChuteOnBuilding)
{
return ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.AstronautComplex) >= (CustomBarnKit.customGameVariables.unlockedEVAChute - 1.1) / (CustomBarnKit.customGameVariables.levelsAstronauts - 1);
}
else
{
return crewMember.experience >= CustomBarnKit.customGameVariables.unlockedEVAChute;
}
}
public override bool UnlockedFlightPlanning(float mCtrlNormLevel)
{
return mCtrlNormLevel > (unlockedFlightPlanning - 1.1) / (levelsMission - 1);
}
public override bool UnlockedFuelTransfer(float editorNormLevel)
{
return editorNormLevel > (unlockedFuelTransfer - 1.1) / (levelsRnD - 1);
}
public override bool UnlockedSpaceObjectDiscovery(float tsNormLevel)
{
return tsNormLevel > (unlockedSpaceObjectDiscovery - 1.1) / (levelsTracking - 1);
}
public override OrbitDisplayMode GetOrbitDisplayMode(float tsNormLevel)
{
if (orbitDisplayMode == null || orbitDisplayMode.Length != levelsTracking)
{
debugLog("orbitDisplayMode wrong size");
return original.GetOrbitDisplayMode(tsNormLevel);
}
return (OrbitDisplayMode)NormLevelToArrayValue(tsNormLevel, orbitDisplayMode);
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("CustomGameVariables");
sb.AppendLine("levelsVAB " + levelsVAB);
sb.AppendLine("VABUpgrades " + DumpArray(upgradesVAB));
sb.AppendLine("upgradesVisualVAB " + DumpArray(upgradesVisualVAB));
sb.AppendLine("actionGroupsStockUnlockVAB " + actionGroupsStockUnlockVAB.ToString("F2"));
sb.AppendLine("actionGroupsCustomUnlockVAB " + actionGroupsCustomUnlockVAB.ToString("F2"));
sb.AppendLine("partCountLimitVAB " + DumpArray(partCountLimitVAB));
sb.AppendLine("levelsSPH " + levelsSPH);
sb.AppendLine("SPHUpgrades " + DumpArray(upgradesSPH));
sb.AppendLine("upgradesVisualSPH " + DumpArray(upgradesVisualSPH));
sb.AppendLine("actionGroupsCustomUnlockSPH " + actionGroupsCustomUnlockSPH.ToString("F2"));
sb.AppendLine("actionGroupsStockUnlockSPH " + actionGroupsStockUnlockSPH.ToString("F2"));
sb.AppendLine("partCountLimitSPH " + DumpArray(partCountLimitSPH));
sb.AppendLine("levelsLaunchPad " + levelsLaunchPad);
sb.AppendLine("upgradesLaunchPad " + DumpArray(upgradesLaunchPad));
sb.AppendLine("upgradesVisualLaunchPad " + DumpArray(upgradesVisualLaunchPad));
sb.AppendLine("craftMassLimitLaunchPad " + DumpArray(craftMassLimitLaunchPad));
sb.AppendLine("craftSizeLimitLaunchPad " + DumpArray(craftSizeLimitLaunchPad));
sb.AppendLine("useBuildingLaunchPad " + useBuildingLaunchPad);
sb.AppendLine("levelsRunway " + levelsRunway);
sb.AppendLine("upgradesRunway " + DumpArray(upgradesRunway));
sb.AppendLine("upgradesVisualRunway " + DumpArray(upgradesVisualRunway));
sb.AppendLine("craftMassLimitRunway " + DumpArray(craftMassLimitRunway));
sb.AppendLine("craftSizeLimitRunway " + DumpArray(craftSizeLimitRunway));
sb.AppendLine("useBuildingRunway " + useBuildingRunway);
sb.AppendLine("levelsAstronauts " + levelsAstronauts);
sb.AppendLine("upgradesAstronauts " + DumpArray(upgradesAstronauts));
sb.AppendLine("upgradesVisualAstronauts " + DumpArray(upgradesVisualAstronauts));
sb.AppendLine("recruitHireBaseCost " + recruitHireBaseCost.ToString("F2"));
sb.AppendLine("recruitHireFlatRate " + recruitHireFlatRate.ToString("F2"));
sb.AppendLine("recruitHireRateModifier " + recruitHireRateModifier.ToString("F2"));
sb.AppendLine("unlockedEVA " + unlockedEVA.ToString("F2"));
sb.AppendLine("unlockedEVAClamber " + unlockedEVAClamber.ToString("F2"));
sb.AppendLine("unlockedEVAFlags " + unlockedEVAFlags.ToString("F2"));
sb.AppendLine("activeCrewLimit " + DumpArray(activeCrewLimit));
sb.AppendLine("crewLevelLimit " + DumpArray(crewLevelLimit));
sb.AppendLine("levelsMission " + levelsMission);
sb.AppendLine("upgradesMission " + DumpArray(upgradesMission));
sb.AppendLine("upgradesVisualMission " + DumpArray(upgradesVisualMission));
sb.AppendLine("unlockedFlightPlanning " + unlockedFlightPlanning.ToString("F2"));
sb.AppendLine("activeContractsLimit " + DumpArray(activeContractsLimit));
sb.AppendLine("scoreSituationCustom " + DumpArray(scoreSituationCustom));
sb.AppendLine("scoreSituationHome " + DumpArray(scoreSituationHome));
sb.AppendLine("scoreSituationOther " + DumpArray(scoreSituationOther));
sb.AppendLine("partRecoveryValueFactor " + partRecoveryValueFactor.ToString("F2"));
sb.AppendLine("resourceRecoveryValueFactor " + resourceRecoveryValueFactor.ToString("F2"));
sb.AppendLine("reputationKerbalDeath " + reputationKerbalDeath.ToString("F2"));
sb.AppendLine("reputationKerbalRecovery " + reputationKerbalRecovery.ToString("F2"));
sb.AppendLine("contractPrestigeTrivial " + contractPrestigeTrivial.ToString("F2"));
sb.AppendLine("contractPrestigeSignificant " + contractPrestigeSignificant.ToString("F2"));
sb.AppendLine("contractPrestigeExceptional " + contractPrestigeExceptional.ToString("F2"));
sb.AppendLine("contractDestinationWeight " + contractDestinationWeight.ToString("F2"));
sb.AppendLine("contractFundsAdvanceFactor " + contractFundsAdvanceFactor.ToString("F2"));
sb.AppendLine("contractFundsCompletionFactor " + contractFundsCompletionFactor.ToString("F2"));
sb.AppendLine("contractFundsFailureFactor " + contractFundsFailureFactor.ToString("F2"));
sb.AppendLine("contractReputationCompletionFactor " + contractReputationCompletionFactor.ToString("F2"));
sb.AppendLine("contractReputationFailureFactor " + contractReputationFailureFactor.ToString("F2"));
sb.AppendLine("contractScienceCompletionFactor " + contractScienceCompletionFactor.ToString("F2"));
sb.AppendLine("levelsTracking " + levelsTracking);
sb.AppendLine("upgradesTracking " + DumpArray(upgradesTracking));
sb.AppendLine("upgradesVisualTracking " + DumpArray(upgradesVisualTracking));
sb.AppendLine("unlockedSpaceObjectDiscovery " + unlockedSpaceObjectDiscovery.ToString("F2"));
sb.AppendLine("orbitDisplayMode " + DumpArray(orbitDisplayMode));
sb.AppendLine("patchesAheadLimit " + DumpArray(patchesAheadLimit));
sb.AppendLine("trackedObjectLimit " + DumpArray(trackedObjectLimit));
sb.AppendLine("DSNRange " + DumpArray(DSNRange));
sb.AppendLine("levelsAdministration " + levelsAdministration);
sb.AppendLine("upgradesAdministration " + DumpArray(upgradesAdministration));
sb.AppendLine("upgradesAdministration " + DumpArray(upgradesVisualAdministration));
sb.AppendLine("activeStrategyLimit " + DumpArray(activeStrategyLimit));
sb.AppendLine("strategyCommitRange " + DumpArray(strategyCommitRange));
sb.AppendLine("levelsRnD " + levelsRnD);
sb.AppendLine("upgradesRnD " + DumpArray(upgradesRnD));
sb.AppendLine("upgradesVisualRnD " + DumpArray(upgradesVisualRnD));
sb.AppendLine("dataToScienceRatio " + DumpArray(dataToScienceRatio));
sb.AppendLine("scienceCostLimit " + DumpArray(scienceCostLimit));
sb.AppendLine("unlockedFuelTransfer " + unlockedFuelTransfer.ToString("F2"));
return sb.ToString();
}
private void debugLog(string s)
{
if (debug)
{
CustomBarnKit.log(s);
}
}
private string DumpArray<T>(IEnumerable<T> array)
{
return array != null ? string.Join(", ", array.Select(x => x.ToString()).ToArray()) : "null";
}
private string DumpArray(IEnumerable<float> array)
{
return array != null ? string.Join(", ", array.Select(x => x.ToString("F2")).ToArray()) : "null";
}
private static T NormLevelToArrayValue<T>(float normLevel, T[] array)
{
int index = Mathf.RoundToInt(normLevel * (array.Length - 1));
index = Mathf.Clamp(index, 0, array.Length - 1); // better safe than sorry
return array[index];
}
private static void LoadValue(ConfigNode node, string key, ref bool param)
{
if (node.HasValue(key))
{
string s = node.GetValue(key);
bool val;
if (bool.TryParse(s, out val))
{
param = val;
}
else
{
CustomBarnKit.log("Fail to parse \"" + s + "\" into a param for key " + key);
}
}
else if (debug)
{
CustomBarnKit.log("No value " + key);
}
}
private static void LoadValue(ConfigNode node, string key, ref float param)
{
if (node.HasValue(key))
{
string s = node.GetValue(key);
float val;
if (float.TryParse(s, out val))
{
param = val >= 0 ? val : float.MaxValue;
}
else
{
CustomBarnKit.log("Fail to parse \"" + s + "\" into a float for key " + key);
}
}
else if (debug)
{
CustomBarnKit.log("No value " + key);
}
}
private static void LoadValue(ConfigNode node, string key, ref int param)
{
if (node.HasValue(key))
{
string s = node.GetValue(key);
int val;
if (int.TryParse(s, out val))
{
param = val != -1 ? val : int.MaxValue;
}
else
{
CustomBarnKit.log("Fail to parse \"" + s + "\" into an int for key " + key);
}
}
else if (debug)
{
CustomBarnKit.log("No value " + key);
}
}
private static void LoadValue(ConfigNode node, string key, ref float[] param)
{
if (node.HasValue(key))
{
string s = node.GetValue(key);
string[] split = s.Split(',');
float[] result = new float[split.Length];
for (int i = 0; i < split.Length; i++)
{
string v = split[i];
float val;
if (float.TryParse(v, out val))
{
result[i] = val >= 0 ? val : float.MaxValue;
}
else
{
CustomBarnKit.log("Fail to parse \"" + s + "\" into a float array for key " + key);
return;
}
}
param = result;
}
else if (debug)
{
CustomBarnKit.log("No value " + key);
}
}
private static void LoadValue(ConfigNode node, string key, ref double[] param)
{
if (node.HasValue(key))
{
string s = node.GetValue(key);
string[] split = s.Split(',');
double[] result = new double[split.Length];
for (int i = 0; i < split.Length; i++)
{
string v = split[i];
double val;
if (double.TryParse(v, out val))
{
result[i] = val >= 0 ? val : double.MaxValue;
}
else
{
CustomBarnKit.log("Fail to parse \"" + s + "\" into a double array for key " + key);
return;
}
}
param = result;
}
else if (debug)
{
CustomBarnKit.log("No value " + key);
}
}
private static void LoadValue(ConfigNode node, string key, ref int[] param)
{
if (node.HasValue(key))
{
string s = node.GetValue(key);
string[] split = s.Split(',');
int[] result = new int[split.Length];
for (int i = 0; i < split.Length; i++)
{
string v = split[i];
int val;
if (int.TryParse(v, out val))
{
result[i] = val >= 0 ? val : int.MaxValue;
}
else
{
CustomBarnKit.log("Fail to parse \"" + s + "\" into an int array for key " + key);
return;
}
}
param = result;
}
else if (debug)
{
CustomBarnKit.log("No value " + key);
}
}
private static readonly Vector3 maxVector3d = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
private static void LoadValue(ConfigNode node, string key, ref Vector3[] param)
{
if (node.HasNode(key))
{
ConfigNode subnode = node.GetNode(key);
if (subnode.HasValue("size"))
{
string[] values = subnode.GetValues("size");
Vector3[] result = new Vector3[values.Length];
for (int i = 0; i < values.Length; i++)
{
result[i] = ConfigNode.ParseVector3(values[i]);
if (result[i].x < 0 && result[i].y < 0 && result[i].z < 0)
{
result[i] = maxVector3d;
}
if (result[i] == Vector3.zero)
{
CustomBarnKit.log("Fail to parse into a Vector array for key " + key + " the node\n" + subnode.ToString());
return;
}
}
param = result;
}
}
else if (debug)
{
CustomBarnKit.log("No node " + key);