Add Population Target and more deriveds
This commit is contained in:
		@@ -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; }
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -10,7 +10,6 @@
 | 
			
		||||
 | 
			
		||||
  <DataGrid x:Name="PlanetsGrid"
 | 
			
		||||
    ItemsSource="{Binding Planets}"
 | 
			
		||||
    IsReadOnly="True" 
 | 
			
		||||
    GridLinesVisibility="All"
 | 
			
		||||
    FrozenColumnCount="1"
 | 
			
		||||
    BorderThickness="1" BorderBrush="Gray">
 | 
			
		||||
@@ -22,7 +21,7 @@
 | 
			
		||||
        <!-- Pop To Ship -->
 | 
			
		||||
        <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
 | 
			
		||||
        <!-- Pop en route -->
 | 
			
		||||
        <!-- Pop Target % -->
 | 
			
		||||
        <DataGridTextColumn Header="Pop Tgt %" Binding="{Binding PopulationTargetPercent}" />
 | 
			
		||||
        <DataGridTextColumn Header="Pop%" Binding="{Binding CapacityPercent}" />
 | 
			
		||||
        <!-- Terra Delta assumed -->
 | 
			
		||||
        <DataGridTextColumn Header="Value" Binding="{Binding Value}" />
 | 
			
		||||
@@ -48,7 +47,7 @@
 | 
			
		||||
        <DataGridTextColumn Header="Fact" Binding="{Binding Factories}" />
 | 
			
		||||
        <DataGridTextColumn Header="Res" Binding="{Binding Resources}" />
 | 
			
		||||
        <!-- Overcrowding Rate -->
 | 
			
		||||
        <!-- Target population absolute -->
 | 
			
		||||
        <DataGridTextColumn Header="Pop Tgt" Binding="{Binding PopulationTarget}" />
 | 
			
		||||
    </DataGrid.Columns>
 | 
			
		||||
  </DataGrid>
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user