2024-07-19 17:08:37 +00:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-07-19 20:00:13 +00:00
|
|
|
|
using System.Globalization;
|
2024-07-19 17:08:37 +00:00
|
|
|
|
|
2024-08-15 19:46:43 +00:00
|
|
|
|
namespace StarsAssistant.Model;
|
2024-07-19 17:08:37 +00:00
|
|
|
|
|
|
|
|
|
public class Planet
|
|
|
|
|
{
|
2024-08-18 17:21:18 +00:00
|
|
|
|
#region Persistant and derived propeties
|
|
|
|
|
|
2024-08-17 14:52:31 +00:00
|
|
|
|
public const int MinEffectiveValue = 5;
|
|
|
|
|
|
2024-08-15 20:17:12 +00:00
|
|
|
|
[Key]
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public required string Name { get; set; }
|
|
|
|
|
|
2024-08-18 17:21:18 +00:00
|
|
|
|
public string? OwnerId { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public string? StarbaseType { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int ReportAge { get; set; } = 0;
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? Population { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? Value { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? Mines { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? Factories { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public decimal? DefPercent { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? SurfaceIronium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? SurfaceBoranium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? SurfaceGermanium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? MRIronium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? MRBoranium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? MRGermanium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? MCIronium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? MCBoranium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-08-15 20:17:12 +00:00
|
|
|
|
public int? MCGermanium { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? Resources { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public decimal? Gravity { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public decimal? Temperature { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public decimal? Radiation { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public decimal? GravityOrig { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public decimal? TemperatureOrig { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public decimal? RadiationOrig { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? MaxTerraforming { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? CapacityPercent { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? ScanRange { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? PenScanRange { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? Driver { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? DriverWarp { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public string? RouteTarget { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? GateRange { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? GateMass { get; set; }
|
2024-07-19 20:00:13 +00:00
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
public int? PctDamage { get; set; }
|
2024-08-18 17:21:18 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Relationships
|
|
|
|
|
|
|
|
|
|
public Race? Owner { get; set; }
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Derived Properties
|
|
|
|
|
|
2024-08-20 14:43:23 +00:00
|
|
|
|
public static int EffectiveValue(int? value) {
|
|
|
|
|
if (value == null) return 0;
|
|
|
|
|
if (value < MinEffectiveValue) return MinEffectiveValue;
|
|
|
|
|
return (int) value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int EffectiveValue() => EffectiveValue(Value);
|
2024-08-18 17:21:18 +00:00
|
|
|
|
|
2024-08-20 14:43:23 +00:00
|
|
|
|
public static int MaxPopOnPlanet (int? value) {
|
|
|
|
|
return Race.Player.MaxPopOnPlanet * EffectiveValue(value) / 100;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int MaxPopOnPlanet() => MaxPopOnPlanet(Value);
|
2024-08-18 17:21:18 +00:00
|
|
|
|
|
|
|
|
|
public int PopGrowth(int currentPop, int maxPop, int value) {
|
|
|
|
|
// What to do with non player races?
|
|
|
|
|
if (OwnerId != Race.Player.Name) return 0;
|
|
|
|
|
|
|
|
|
|
double popRatio = currentPop / maxPop;
|
|
|
|
|
int growth = 0;
|
|
|
|
|
if (value < 0)
|
|
|
|
|
growth = currentPop * value / 10;
|
|
|
|
|
else if (popRatio <= 0.25)
|
|
|
|
|
growth = currentPop * value * (Race.Player.GrowthRatePercent ?? 0) / 100;
|
|
|
|
|
else if (popRatio <= 1)
|
|
|
|
|
growth = currentPop * value * (Race.Player.GrowthRatePercent ?? 0) /100 * 16 / 9 * ((int) Math.Pow(1 - popRatio, 2));
|
|
|
|
|
else
|
|
|
|
|
growth = (int) (currentPop * (popRatio - 1) * 0.04);
|
|
|
|
|
|
|
|
|
|
return growth / 100 * 100;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-20 14:43:23 +00:00
|
|
|
|
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);
|
2024-08-18 17:21:18 +00:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2024-07-19 17:08:37 +00:00
|
|
|
|
}
|