Finish Owner Relationship, update races and add first helpers for derived values. Update naming
This commit is contained in:
		@@ -5,12 +5,14 @@ namespace StarsAssistant.Model;
 | 
			
		||||
 | 
			
		||||
public class Planet
 | 
			
		||||
{
 | 
			
		||||
    #region Persistant and derived propeties
 | 
			
		||||
 | 
			
		||||
    public const int MinEffectiveValue = 5;
 | 
			
		||||
 | 
			
		||||
    [Key]
 | 
			
		||||
    public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
    public string? Owner { get; set; }
 | 
			
		||||
    public string? OwnerId { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    public string? StarbaseType { get; set; }
 | 
			
		||||
    
 | 
			
		||||
@@ -77,4 +79,41 @@ public class Planet
 | 
			
		||||
    public int? GateMass { get; set; }
 | 
			
		||||
    
 | 
			
		||||
    public int? PctDamage { get; set; }
 | 
			
		||||
 | 
			
		||||
    #endregion
 | 
			
		||||
 | 
			
		||||
    #region Relationships
 | 
			
		||||
 | 
			
		||||
    public Race? Owner { get; set; }
 | 
			
		||||
 | 
			
		||||
    #endregion
 | 
			
		||||
 | 
			
		||||
    #region Derived Properties
 | 
			
		||||
 | 
			
		||||
    public int EffectiveValue => (Value == null) ? 0 : Math.Max((int)Value, MinEffectiveValue);
 | 
			
		||||
 | 
			
		||||
    public int MaxPopOnPlanet => Race.Player.MaxPopOnPlanet * EffectiveValue / 100;
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public int PopGrowth() => PopGrowth(Population ?? 0, MaxPopOnPlanet, Value ?? 0);
 | 
			
		||||
 | 
			
		||||
    #endregion
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -15,14 +15,18 @@ public enum PRT {
 | 
			
		||||
 | 
			
		||||
public class Race
 | 
			
		||||
{
 | 
			
		||||
    #region Persistant and derived properties
 | 
			
		||||
 | 
			
		||||
    [Key]
 | 
			
		||||
    public required string Name { get; set; }
 | 
			
		||||
 | 
			
		||||
    public int ColonistsPerResource { get; set; }
 | 
			
		||||
    public bool PlayerRace { get; set; } = false;
 | 
			
		||||
 | 
			
		||||
    public int GrowthRatePercent { get; set; }
 | 
			
		||||
    public int? ColonistsPerResource { get; set; }
 | 
			
		||||
 | 
			
		||||
    private PRT _PRT;
 | 
			
		||||
    public int? GrowthRatePercent { get; set; }
 | 
			
		||||
 | 
			
		||||
    private PRT _PRT = PRT.Other;
 | 
			
		||||
    public PRT PRT { 
 | 
			
		||||
        get => _PRT; 
 | 
			
		||||
        set {
 | 
			
		||||
@@ -31,8 +35,8 @@ public class Race
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private bool _hasOBRM;
 | 
			
		||||
    public bool HasOBRM { 
 | 
			
		||||
    private bool? _hasOBRM;
 | 
			
		||||
    public bool? HasOBRM { 
 | 
			
		||||
        get => _hasOBRM; 
 | 
			
		||||
        set {
 | 
			
		||||
            _hasOBRM = value;
 | 
			
		||||
@@ -49,29 +53,50 @@ public class Race
 | 
			
		||||
    [NotMapped]
 | 
			
		||||
    public int MaxEffectivePopOnGreen { get; private set; }
 | 
			
		||||
 | 
			
		||||
    private bool _factoryCost3;
 | 
			
		||||
    public bool FactoryCost3 { 
 | 
			
		||||
    private bool? _factoryCost3;
 | 
			
		||||
    public bool? FactoryCost3 { 
 | 
			
		||||
        get => _factoryCost3; 
 | 
			
		||||
        set {
 | 
			
		||||
            _factoryCost3 = value;
 | 
			
		||||
            FactoryGerCost = _factoryCost3 ? 3 : 4;
 | 
			
		||||
            FactoryGerCost = (_factoryCost3 ?? false) ? 3 : 4;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [NotMapped]
 | 
			
		||||
    public int FactoryGerCost { get; private set; }
 | 
			
		||||
 | 
			
		||||
    public int FactoryNumberPer10k { get; set; }
 | 
			
		||||
    public int? FactoryNumberPer10k { get; set; }
 | 
			
		||||
 | 
			
		||||
    public int FactoryResCost { get; set; }
 | 
			
		||||
    public int? FactoryResCost { get; set; }
 | 
			
		||||
 | 
			
		||||
    public int FactoryResPer10 { get; set; }
 | 
			
		||||
    public int? FactoryResPer10 { get; set; }
 | 
			
		||||
 | 
			
		||||
    public int MineResCost { get; set; }
 | 
			
		||||
    public int? MineResCost { get; set; }
 | 
			
		||||
 | 
			
		||||
    public int MineNumberPer10k { get; set; }
 | 
			
		||||
    public int? MineNumberPer10k { get; set; }
 | 
			
		||||
 | 
			
		||||
    public int MineMineralsPer10 { get; set; }
 | 
			
		||||
    public int? MineMineralsPer10 { get; set; }
 | 
			
		||||
 | 
			
		||||
    #endregion
 | 
			
		||||
 | 
			
		||||
    #region Relationships
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
 | 
			
		||||
    #endregion
 | 
			
		||||
 | 
			
		||||
    #region Internal Helpers
 | 
			
		||||
 | 
			
		||||
    private void UpdatePopDerivedValues() {
 | 
			
		||||
        const int basePop = 1_000_000;
 | 
			
		||||
@@ -81,10 +106,11 @@ public class Race
 | 
			
		||||
            PRT.JOAT => 1.2,
 | 
			
		||||
            _ => 1,
 | 
			
		||||
        };
 | 
			
		||||
        double obrmMod = HasOBRM ? 1.1 : 1.0;
 | 
			
		||||
        double obrmMod = (HasOBRM ?? false) ? 1.1 : 1.0;
 | 
			
		||||
        MaxPopOnPlanet = Convert.ToInt32(basePop * prtMod * obrmMod);
 | 
			
		||||
        MaxEffectivePopOnRed = MaxPopOnPlanet * Planet.MinEffectiveValue / 100 * 3;
 | 
			
		||||
        MaxEffectivePopOnGreen = MaxPopOnPlanet * 3;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
    #endregion
 | 
			
		||||
}
 | 
			
		||||
@@ -25,12 +25,12 @@ public class StarsDatabase(string DbPath) : DbContext
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// List of all Planets read.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public DbSet<Planet> Planets { get; set; }
 | 
			
		||||
    public DbSet<Planet> Planet { get; set; }
 | 
			
		||||
 | 
			
		||||
    /// <summary>
 | 
			
		||||
    /// Lists of all defined races.
 | 
			
		||||
    /// </summary>
 | 
			
		||||
    public DbSet<Race> Races { get; set; }
 | 
			
		||||
    public DbSet<Race> Race { get; set; }
 | 
			
		||||
 | 
			
		||||
    #endregion
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user