Add further derived properties

This commit is contained in:
Torben Nehmer 2024-08-20 16:43:23 +02:00
parent aff9d23841
commit 76bf032b09
No known key found for this signature in database

View File

@ -90,9 +90,19 @@ public class Planet
#region Derived Properties
public int EffectiveValue => (Value == null) ? 0 : Math.Max((int)Value, MinEffectiveValue);
public static int EffectiveValue(int? value) {
if (value == null) return 0;
if (value < MinEffectiveValue) return MinEffectiveValue;
return (int) value;
}
public int MaxPopOnPlanet => Race.Player.MaxPopOnPlanet * EffectiveValue / 100;
public int EffectiveValue() => EffectiveValue(Value);
public static int MaxPopOnPlanet (int? value) {
return Race.Player.MaxPopOnPlanet * EffectiveValue(value) / 100;
}
public int MaxPopOnPlanet() => MaxPopOnPlanet(Value);
public int PopGrowth(int currentPop, int maxPop, int value) {
// What to do with non player races?
@ -112,7 +122,62 @@ public class Planet
return growth / 100 * 100;
}
public int PopGrowth() => PopGrowth(Population ?? 0, MaxPopOnPlanet, Value ?? 0);
public int PopGrowth() => PopGrowth(Population ?? 0, MaxPopOnPlanet(), Value ?? 0);
public int MaxFact(int currentPop) {
int effectivePop = Math.Min(currentPop, MaxPopOnPlanet());
double tmp = (double) effectivePop / 10000 * Race.Player.FactoryNumberPer10k ?? 0;
return (int) tmp;
}
public int MaxFact() => MaxFact(Population ?? 0);
public int MaxMines(int currentPop) {
int effectivePop = Math.Min(currentPop, MaxPopOnPlanet());
double tmp = (double) effectivePop / 10000 * Race.Player.MineNumberPer10k ?? 0;
return (int) tmp;
}
public int MaxMines() => MaxMines(Population ?? 0);
public static int ResourcesFromPop(int currentPop, int value) {
if (Race.Player.ColonistsPerResource == null
|| Race.Player.ColonistsPerResource == 0)
{
return 0;
}
int maxPop = MaxPopOnPlanet(value);
int popFullEfficiency = 0;
int popHalfEfficiency = 0;
if (currentPop <= maxPop) {
popFullEfficiency = currentPop;
}
else if (currentPop <= 3 * maxPop) {
popFullEfficiency = maxPop;
popHalfEfficiency = currentPop - maxPop;
}
else {
popFullEfficiency = maxPop;
popHalfEfficiency = 2 * maxPop;
}
int popEffective = popFullEfficiency + (popHalfEfficiency / 2);
return (popEffective / Race.Player.ColonistsPerResource) ?? 0;
}
public int ResourcesFromPop() => ResourcesFromPop(Population ?? 0, Value ?? 0);
public static int ResourcesFromFact(int currentPop, int factories, int value) {
int maxPop = MaxPopOnPlanet(value);
int effectivePop = Math.Min(currentPop, maxPop);
double tmp = (double) effectivePop / 10000 * Race.Player.FactoryNumberPer10k ?? 0;
int maxOperableFactories = (int) tmp;
int operableFactories = Math.Min(factories, maxOperableFactories);
tmp = (double) operableFactories / 10 * Race.Player.FactoryResPer10 ?? 0;
return (int) tmp;
}
public int ResourcesFromFact() => ResourcesFromFact(Population ?? 0, Factories ?? 0, Value ?? 0);
#endregion