Move player to game engine.

This commit is contained in:
2024-09-21 14:40:13 +02:00
parent 63761001fa
commit e01a50ec9c
5 changed files with 30 additions and 21 deletions

View File

@ -99,23 +99,23 @@ public class Planet
public int EffectiveValue() => EffectiveValue(Value);
public static int MaxPopOnPlanet (int? value) {
return Race.Player.MaxPopOnPlanet * EffectiveValue(value) / 100;
return Services.Game.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?
if (OwnerId != Race.Player.Name) return 0;
if (OwnerId != Services.Game.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;
growth = currentPop * value * (Services.Game.Player.GrowthRatePercent ?? 0) / 100;
else if (popRatio <= 1)
growth = currentPop * value * (Race.Player.GrowthRatePercent ?? 0) /100 * 16 / 9 * ((int) Math.Pow(1 - popRatio, 2));
growth = currentPop * value * (Services.Game.Player.GrowthRatePercent ?? 0) /100 * 16 / 9 * ((int) Math.Pow(1 - popRatio, 2));
else
growth = (int) (currentPop * (popRatio - 1) * 0.04);
@ -126,7 +126,7 @@ public class Planet
public int MaxFact(int currentPop) {
int effectivePop = Math.Min(currentPop, MaxPopOnPlanet());
double tmp = (double) effectivePop / 10000 * Race.Player.FactoryNumberPer10k ?? 0;
double tmp = (double) effectivePop / 10000 * Services.Game.Player.FactoryNumberPer10k ?? 0;
return (int) tmp;
}
@ -134,15 +134,15 @@ public class Planet
public int MaxMines(int currentPop) {
int effectivePop = Math.Min(currentPop, MaxPopOnPlanet());
double tmp = (double) effectivePop / 10000 * Race.Player.MineNumberPer10k ?? 0;
double tmp = (double) effectivePop / 10000 * Services.Game.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)
if (Services.Game.Player.ColonistsPerResource == null
|| Services.Game.Player.ColonistsPerResource == 0)
{
return 0;
}
@ -162,7 +162,7 @@ public class Planet
popHalfEfficiency = 2 * maxPop;
}
int popEffective = popFullEfficiency + (popHalfEfficiency / 2);
return (popEffective / Race.Player.ColonistsPerResource) ?? 0;
return (popEffective / Services.Game.Player.ColonistsPerResource) ?? 0;
}
public int ResourcesFromPop() => ResourcesFromPop(Population ?? 0, Value ?? 0);
@ -170,10 +170,10 @@ public class Planet
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;
double tmp = (double) effectivePop / 10000 * Services.Game.Player.FactoryNumberPer10k ?? 0;
int maxOperableFactories = (int) tmp;
int operableFactories = Math.Min(factories, maxOperableFactories);
tmp = (double) operableFactories / 10 * Race.Player.FactoryResPer10 ?? 0;
tmp = (double) operableFactories / 10 * Services.Game.Player.FactoryResPer10 ?? 0;
return (int) tmp;
}

View File

@ -85,13 +85,6 @@ public class Race
public ICollection<Planet> Planets { get; } = new List<Planet>();
// TODO: Implement Lazy Loader, currently hardcoded in testing startup code
public static Race _player = null!;
public static Race Player {
get => _player;
set => _player = value;
}
#endregion
#region Public Helpers