Add Population Target and more deriveds
This commit is contained in:
		@@ -5,7 +5,7 @@ namespace StarsAssistant.Model;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class Planet
 | 
					public class Planet
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    #region Persistant propeties
 | 
					    #region Persistant propeties (from Stars)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    [Key]
 | 
					    [Key]
 | 
				
			||||||
    public required string Name { get; set; }
 | 
					    public required string Name { get; set; }
 | 
				
			||||||
@@ -80,6 +80,13 @@ public class Planet
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #region Planning Properties
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public int PopulationTargetPercent { get; set; } = 100;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region Relationships
 | 
					    #region Relationships
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Race? Owner { get; set; }
 | 
					    public Race? Owner { get; set; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -40,7 +40,7 @@ public class GameEngine
 | 
				
			|||||||
    public static int PlanetPopGrowthForPlayer(int currentPop, int value) 
 | 
					    public static int PlanetPopGrowthForPlayer(int currentPop, int value) 
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        int maxPop = MaxPopOnPlanetForPlayer(value);
 | 
					        int maxPop = MaxPopOnPlanetForPlayer(value);
 | 
				
			||||||
        double growth;
 | 
					        int growth;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (value < 0)
 | 
					        if (value < 0)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -50,15 +50,29 @@ public class GameEngine
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            double popRatio = (double) currentPop / maxPop;
 | 
					            double popRatio = (double) currentPop / maxPop;
 | 
				
			||||||
            if (popRatio <= 0.25) 
 | 
					            if (popRatio <= 0.25) 
 | 
				
			||||||
                growth = currentPop * value / 100.0 * Game.Player.GrowthRatePercent / 100.0;
 | 
					            {
 | 
				
			||||||
            else if (popRatio <= 1)
 | 
					                growth = currentPop 
 | 
				
			||||||
                growth = currentPop * value / 100.0 * Game.Player.GrowthRatePercent / 100.0 * 16.0 / 9.0 * Math.Pow(1.0 - popRatio, 2);
 | 
					                    * 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 
 | 
					            else 
 | 
				
			||||||
                growth = currentPop * (popRatio - 1) * 0.04;
 | 
					            {
 | 
				
			||||||
 | 
					                double factor = 0.04 * (popRatio - 1);
 | 
				
			||||||
 | 
					                growth = (int) ((double) currentPop * factor);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // round to nearest 100
 | 
					        // round down by 100
 | 
				
			||||||
        return ((int) growth) / 100 * 100;
 | 
					        return growth / 100 * 100;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /// <summary>
 | 
					    /// <summary>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,9 @@
 | 
				
			|||||||
using System.Collections.ObjectModel;
 | 
					using System.Collections.ObjectModel;
 | 
				
			||||||
using System.Reactive.Disposables;
 | 
					using System.Reactive.Disposables;
 | 
				
			||||||
 | 
					using System.Reactive.Linq;
 | 
				
			||||||
using Microsoft.EntityFrameworkCore;
 | 
					using Microsoft.EntityFrameworkCore;
 | 
				
			||||||
using ReactiveUI;
 | 
					using ReactiveUI;
 | 
				
			||||||
 | 
					using ReactiveUI.SourceGenerators;
 | 
				
			||||||
using StarsAssistant.Services;
 | 
					using StarsAssistant.Services;
 | 
				
			||||||
using Splat;
 | 
					using Splat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -21,6 +23,12 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
            throw new InvalidOperationException("PlayerPlanet ViewModels can only be created for player planets.");
 | 
					            throw new InvalidOperationException("PlayerPlanet ViewModels can only be created for player planets.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Planet = planet;
 | 
					        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) => 
 | 
					        this.WhenActivated((CompositeDisposable disposables) => 
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
@@ -101,6 +109,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public int PctDamage => Planet.PctDamage ?? 0;
 | 
					    public int PctDamage => Planet.PctDamage ?? 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [Reactive]
 | 
				
			||||||
 | 
					    private int _populationTargetPercent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #region Derived Properties
 | 
					    #region Derived Properties
 | 
				
			||||||
@@ -123,6 +134,9 @@ public partial class PlayerPlanetViewModel : ViewModelBase
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public int ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value);
 | 
					    public int ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    [ObservableAsProperty]
 | 
				
			||||||
 | 
					    private int _populationTarget;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #endregion
 | 
					    #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -10,7 +10,6 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  <DataGrid x:Name="PlanetsGrid"
 | 
					  <DataGrid x:Name="PlanetsGrid"
 | 
				
			||||||
    ItemsSource="{Binding Planets}"
 | 
					    ItemsSource="{Binding Planets}"
 | 
				
			||||||
    IsReadOnly="True" 
 | 
					 | 
				
			||||||
    GridLinesVisibility="All"
 | 
					    GridLinesVisibility="All"
 | 
				
			||||||
    FrozenColumnCount="1"
 | 
					    FrozenColumnCount="1"
 | 
				
			||||||
    BorderThickness="1" BorderBrush="Gray">
 | 
					    BorderThickness="1" BorderBrush="Gray">
 | 
				
			||||||
@@ -22,7 +21,7 @@
 | 
				
			|||||||
        <!-- Pop To Ship -->
 | 
					        <!-- Pop To Ship -->
 | 
				
			||||||
        <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
 | 
					        <DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
 | 
				
			||||||
        <!-- Pop en route -->
 | 
					        <!-- Pop en route -->
 | 
				
			||||||
        <!-- Pop Target % -->
 | 
					        <DataGridTextColumn Header="Pop Tgt %" Binding="{Binding PopulationTargetPercent}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Pop%" Binding="{Binding CapacityPercent}" />
 | 
					        <DataGridTextColumn Header="Pop%" Binding="{Binding CapacityPercent}" />
 | 
				
			||||||
        <!-- Terra Delta assumed -->
 | 
					        <!-- Terra Delta assumed -->
 | 
				
			||||||
        <DataGridTextColumn Header="Value" Binding="{Binding Value}" />
 | 
					        <DataGridTextColumn Header="Value" Binding="{Binding Value}" />
 | 
				
			||||||
@@ -48,7 +47,7 @@
 | 
				
			|||||||
        <DataGridTextColumn Header="Fact" Binding="{Binding Factories}" />
 | 
					        <DataGridTextColumn Header="Fact" Binding="{Binding Factories}" />
 | 
				
			||||||
        <DataGridTextColumn Header="Res" Binding="{Binding Resources}" />
 | 
					        <DataGridTextColumn Header="Res" Binding="{Binding Resources}" />
 | 
				
			||||||
        <!-- Overcrowding Rate -->
 | 
					        <!-- Overcrowding Rate -->
 | 
				
			||||||
        <!-- Target population absolute -->
 | 
					        <DataGridTextColumn Header="Pop Tgt" Binding="{Binding PopulationTarget}" />
 | 
				
			||||||
    </DataGrid.Columns>
 | 
					    </DataGrid.Columns>
 | 
				
			||||||
  </DataGrid>
 | 
					  </DataGrid>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user