@@ -78,6 +78,45 @@ public static KRnDModule getKRnDModule(Part part)
78
78
return null ;
79
79
}
80
80
81
+ // Parts can have multiple variants which we return as a list, needed
82
+ // because some variants change the part mass
83
+ public static Dictionary < string , KRnDVariant > getVariants ( Part part )
84
+ {
85
+ if ( part == null ) return null ;
86
+ if ( part . partInfo . partPrefab == null ) return null ;
87
+
88
+ if ( part . partInfo . Variants == null ) return null ;
89
+
90
+ Dictionary < string , KRnDVariant > variants = new Dictionary < string , KRnDVariant > ( ) ;
91
+
92
+ for ( int i = 0 ; i < part . partInfo . Variants . Count ; i ++ )
93
+ {
94
+ var partVariant = part . partInfo . Variants [ i ] ;
95
+ KRnDVariant v = new KRnDVariant ( partVariant . Name , partVariant . Mass ) ;
96
+ variants . Add ( partVariant . Name , v ) ;
97
+ }
98
+ return variants ;
99
+ }
100
+
101
+ static void UpdatePartVariantMasses ( Part part , PartStats originalStats , float dryMassFactor )
102
+ {
103
+ if ( part . partInfo . partPrefab == null || part . partInfo . Variants == null )
104
+ return ;
105
+
106
+ if ( originalStats . kRnDVariants == null )
107
+ originalStats . kRnDVariants = new Dictionary < string , KRnDVariant > ( ) ;
108
+
109
+ for ( int i = 0 ; i < part . partInfo . Variants . Count ; i ++ )
110
+ {
111
+ var partVariant = part . partInfo . Variants [ i ] ;
112
+ if ( originalStats . kRnDVariants . TryGetValue ( partVariant . Name , out KRnDVariant v ) == false )
113
+ v = new KRnDVariant ( partVariant . Name , partVariant . Mass ) ;
114
+ v . UpdateMass ( dryMassFactor ) ;
115
+ originalStats . kRnDVariants [ partVariant . Name ] = v ;
116
+ partVariant . Mass = v . mass ;
117
+ }
118
+ }
119
+
81
120
// Multi-Mode engines have multiple Engine-Modules which we return as a list.
82
121
public static List < ModuleEngines > getEngineModules ( Part part )
83
122
{
@@ -497,6 +536,11 @@ public static void updatePart(Part part, KRnDUpgrade upgradesToApply)
497
536
part . mass = originalStats . mass * dryMassFactor ;
498
537
part . prefabMass = part . mass ; // New in ksp 1.1, if this is correct is just guesswork however...
499
538
539
+ part . partInfo . variant . Mass = originalStats . currentVariantMass * dryMassFactor ;
540
+ UpdatePartVariantMasses ( part , originalStats , dryMassFactor ) ;
541
+ part . baseVariant . Mass = originalStats . variantBaseMass * dryMassFactor ;
542
+
543
+
500
544
// Dry Mass also improves fairing mass:
501
545
ModuleProceduralFairing fairngModule = KRnD . getFairingModule ( part ) ;
502
546
if ( fairngModule )
@@ -519,9 +563,9 @@ public static void updatePart(Part part, KRnDUpgrade upgradesToApply)
519
563
for ( int i = 0 ; i < originalStats . maxFuelFlows . Count ; i ++ )
520
564
{
521
565
float maxFuelFlow = originalStats . maxFuelFlows [ i ] * ( 1 + KRnD . calculateImprovementFactor ( rndModule . fuelFlow_improvement , rndModule . fuelFlow_improvementScale , upgradesToApply . fuelFlow ) ) ;
522
- if ( engineModules != null )
566
+ if ( engineModules != null )
523
567
engineModules [ i ] . maxFuelFlow = maxFuelFlow ;
524
- else if ( rcsModule )
568
+ else if ( rcsModule )
525
569
rcsModule . thrusterPower = maxFuelFlow ; // There is only one rcs-module
526
570
}
527
571
}
@@ -645,7 +689,7 @@ public static void updatePart(Part part, KRnDUpgrade upgradesToApply)
645
689
for ( int i = 0 ; i < generator . resHandler . outputResources . Count ; i ++ )
646
690
{
647
691
ModuleResource outputResource = generator . resHandler . outputResources [ i ] ;
648
-
692
+
649
693
double originalRate ;
650
694
if ( ! originalStats . generatorEfficiency . TryGetValue ( outputResource . name , out originalRate ) ) continue ;
651
695
outputResource . rate = ( float ) ( originalRate * ( 1 + KRnD . calculateImprovementFactor ( rndModule . generatorEfficiency_improvement , rndModule . generatorEfficiency_improvementScale , upgradesToApply . generatorEfficiency ) ) ) ;
@@ -670,7 +714,7 @@ public static void updatePart(Part part, KRnDUpgrade upgradesToApply)
670
714
for ( int i = 0 ; i < converterList . Count ; i ++ )
671
715
{
672
716
ModuleResourceConverter converter = converterList [ i ] ;
673
-
717
+
674
718
Dictionary < String , double > origiginalOutputResources ;
675
719
if ( ! originalStats . converterEfficiency . TryGetValue ( converter . ConverterName , out origiginalOutputResources ) ) continue ;
676
720
@@ -711,10 +755,10 @@ public static void updatePart(Part part, KRnDUpgrade upgradesToApply)
711
755
rndModule . fuelCapacity_upgrades = upgradesToApply . fuelCapacity ;
712
756
double improvementFactor = ( 1 + KRnD . calculateImprovementFactor ( rndModule . fuelCapacity_improvement , rndModule . fuelCapacity_improvementScale , upgradesToApply . fuelCapacity ) ) ;
713
757
714
- for ( int i = 0 ; i < fuelResources . Count ; i ++ )
758
+ for ( int i = 0 ; i < fuelResources . Count ; i ++ )
715
759
{
716
760
PartResource fuelResource = fuelResources [ i ] ;
717
-
761
+
718
762
if ( ! originalStats . fuelCapacities . ContainsKey ( fuelResource . resourceName ) ) continue ;
719
763
double originalCapacity = originalStats . fuelCapacities [ fuelResource . resourceName ] ;
720
764
double newCapacity = originalCapacity * improvementFactor ;
@@ -748,13 +792,14 @@ public static void updateVessel(Vessel vessel)
748
792
{
749
793
if ( ! vessel . isActiveVessel ) return ; // Only the currently active vessel matters, the others are not simulated anyway.
750
794
if ( KRnD . upgrades == null ) throw new Exception ( "upgrades-dictionary missing" ) ;
795
+
751
796
Debug . Log ( "[KRnD] updating vessel '" + vessel . vesselName . ToString ( ) + "'" ) ;
752
797
753
798
// Iterate through all parts:
754
799
for ( int i = 0 ; i < vessel . parts . Count ; i ++ )
755
800
{
756
801
Part part = vessel . parts [ i ] ;
757
-
802
+
758
803
// We only have to update parts which have the RnD-Module:
759
804
KRnDModule rndModule = KRnD . getKRnDModule ( part ) ;
760
805
if ( rndModule == null ) continue ;
@@ -811,6 +856,22 @@ private void EditorPartEvent(ConstructionEventType ev, Part part)
811
856
}
812
857
}
813
858
859
+ private void OnVariantApplied ( Part part , PartVariant pv )
860
+ {
861
+ if ( part == null || part != KRnDGUI . selectedPart ) return ;
862
+ foreach ( var v in part . partInfo . Variants )
863
+ {
864
+ if ( v . Name == pv . Name )
865
+ {
866
+ //partStats.currentVariant = p.partInfo.variant.Name;
867
+ //partStats.currentVariantMass = kv.mass;
868
+
869
+ //v.Mass
870
+ break ;
871
+ }
872
+
873
+ }
874
+ }
814
875
public List < string > getBlacklistedModules ( )
815
876
{
816
877
List < string > blacklistedModules = new List < string > ( ) ;
@@ -864,19 +925,19 @@ public void Awake()
864
925
for ( int i = 0 ; i < PartLoader . LoadedPartsList . Count ; i ++ )
865
926
{
866
927
AvailablePart aPart = PartLoader . LoadedPartsList [ i ] ;
867
-
928
+
868
929
Part part = aPart . partPrefab ;
869
930
List < ModuleEngines > engineModules = KRnD . getEngineModules ( part ) ;
870
931
if ( engineModules == null ) continue ;
871
932
for ( int i1 = 0 ; i1 < engineModules . Count ; i1 ++ )
872
933
{
873
934
ModuleEngines engineModule = engineModules [ i1 ] ;
874
-
935
+
875
936
if ( engineModule . propellants == null ) continue ;
876
937
for ( int i2 = 0 ; i2 < engineModule . propellants . Count ; i2 ++ )
877
938
{
878
939
Propellant propellant = engineModule . propellants [ i2 ] ;
879
-
940
+
880
941
if ( propellant . name == "ElectricCharge" ) continue ; // Electric Charge is improved by batteries.
881
942
if ( propellant . name == "IntakeAir" ) continue ; // This is no real fuel-type.
882
943
if ( ! fuelResources . Contains ( propellant . name ) ) fuelResources . Add ( propellant . name ) ;
@@ -888,7 +949,7 @@ public void Awake()
888
949
for ( int i = 0 ; i < KRnD . fuelResources . Count ; i ++ )
889
950
{
890
951
String fuelName = KRnD . fuelResources [ i ] ;
891
-
952
+
892
953
if ( listString != "" ) listString += ", " ;
893
954
listString += fuelName ;
894
955
}
@@ -904,15 +965,15 @@ public void Awake()
904
965
for ( int i = 0 ; i < PartLoader . LoadedPartsList . Count ; i ++ )
905
966
{
906
967
AvailablePart aPart = PartLoader . LoadedPartsList [ i ] ;
907
-
968
+
908
969
Part part = aPart . partPrefab ;
909
970
Boolean skip = false ;
910
971
string blacklistedModule = "N/A" ;
911
972
912
973
for ( int i1 = 0 ; i1 < part . Modules . Count ; i1 ++ )
913
974
{
914
975
PartModule partModule = part . Modules [ i1 ] ;
915
-
976
+
916
977
if ( blacklistedModules . Contains ( partModule . moduleName ) )
917
978
{
918
979
blacklistedModule = partModule . moduleName ;
@@ -965,6 +1026,7 @@ public void Awake()
965
1026
// Register event-handlers:
966
1027
GameEvents . onVesselChange . Add ( this . OnVesselChange ) ;
967
1028
GameEvents . onEditorPartEvent . Add ( this . EditorPartEvent ) ;
1029
+ GameEvents . onVariantApplied . Add ( this . OnVariantApplied ) ;
968
1030
969
1031
KRnD . initialized = true ;
970
1032
}
0 commit comments