diff --git a/Stars Assistant/Model/Planet.cs b/Stars Assistant/Model/Planet.cs index fc657f2..6b5546e 100644 --- a/Stars Assistant/Model/Planet.cs +++ b/Stars Assistant/Model/Planet.cs @@ -5,7 +5,7 @@ namespace StarsAssistant.Model; public class Planet { - #region Persistant propeties + #region Persistant propeties (from Stars) [Key] public required string Name { get; set; } @@ -80,6 +80,13 @@ public class Planet #endregion + #region Planning Properties + + public int PopulationTargetPercent { get; set; } = 100; + + #endregion + + #region Relationships public Race? Owner { get; set; } diff --git a/Stars Assistant/Services/GameEngine.cs b/Stars Assistant/Services/GameEngine.cs index 25db46f..9525035 100644 --- a/Stars Assistant/Services/GameEngine.cs +++ b/Stars Assistant/Services/GameEngine.cs @@ -40,7 +40,7 @@ public class GameEngine public static int PlanetPopGrowthForPlayer(int currentPop, int value) { int maxPop = MaxPopOnPlanetForPlayer(value); - double growth; + int growth; if (value < 0) { @@ -49,16 +49,30 @@ public class GameEngine else { double popRatio = (double) currentPop / maxPop; - if (popRatio <= 0.25) - growth = currentPop * value / 100.0 * Game.Player.GrowthRatePercent / 100.0; - else if (popRatio <= 1) - growth = currentPop * value / 100.0 * Game.Player.GrowthRatePercent / 100.0 * 16.0 / 9.0 * Math.Pow(1.0 - popRatio, 2); - else - growth = currentPop * (popRatio - 1) * 0.04; + if (popRatio <= 0.25) + { + growth = currentPop + * Game.Player.GrowthRatePercent / 100 + * value / 100; + } + else if (popRatio < 1) + { + double factor = Math.Pow(1.0 - popRatio, 2); + growth = currentPop + * Game.Player.GrowthRatePercent / 100 + * value / 100 + * 16 / 9; + growth = (int) ((double) growth * factor); + } + else + { + double factor = 0.04 * (popRatio - 1); + growth = (int) ((double) currentPop * factor); + } } - // round to nearest 100 - return ((int) growth) / 100 * 100; + // round down by 100 + return growth / 100 * 100; } /// diff --git a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs index 84fcf0d..51f335d 100644 --- a/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs +++ b/Stars Assistant/ViewModels/PlayerPlanetViewModel.cs @@ -1,7 +1,9 @@ using System.Collections.ObjectModel; using System.Reactive.Disposables; +using System.Reactive.Linq; using Microsoft.EntityFrameworkCore; using ReactiveUI; +using ReactiveUI.SourceGenerators; using StarsAssistant.Services; using Splat; @@ -21,6 +23,12 @@ public partial class PlayerPlanetViewModel : ViewModelBase throw new InvalidOperationException("PlayerPlanet ViewModels can only be created for player planets."); Planet = planet; + PopulationTargetPercent = planet.PopulationTargetPercent; + + _populationTargetHelper = this + .WhenAnyValue(vm => vm.PopulationTargetPercent) + .Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100) + .ToProperty(this, vm => vm.PopulationTarget); this.WhenActivated((CompositeDisposable disposables) => { @@ -101,6 +109,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase public int PctDamage => Planet.PctDamage ?? 0; + [Reactive] + private int _populationTargetPercent; + #endregion #region Derived Properties @@ -123,6 +134,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase public int ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value); + [ObservableAsProperty] + private int _populationTarget; + #endregion } \ No newline at end of file diff --git a/Stars Assistant/Views/BuColView.axaml b/Stars Assistant/Views/BuColView.axaml index dec6780..36da30f 100644 --- a/Stars Assistant/Views/BuColView.axaml +++ b/Stars Assistant/Views/BuColView.axaml @@ -10,7 +10,6 @@ @@ -22,7 +21,7 @@ - + @@ -48,7 +47,7 @@ - +