BuCol Setup

This commit is contained in:
Torben Nehmer 2024-09-26 22:18:50 +02:00
parent a394918064
commit a03edf8983
8 changed files with 137 additions and 49 deletions

View File

@ -4,6 +4,7 @@ using CsvHelper.Configuration;
using CsvHelper;
using System.Globalization;
using Splat;
using StarsAssistant.Services;
namespace StarsAssistant.CSV;
@ -45,10 +46,10 @@ public class PlanetLoader
/// <param name="race">Import File</param>
public void ImportForRace(Model.Race race)
{
using (var db = Locator.Current.GetService<Model.StarsDatabase>()!)
using (var reader = new StreamReader(Game.PlanetFileForRace(race), System.Text.Encoding.Latin1))
using (var csv = new CsvReader(reader, CsvConfig))
{
using var db = Locator.Current.GetService<Model.StarsDatabase>()!;
using var reader = new StreamReader(Game.PlanetFileForRace(race), System.Text.Encoding.Latin1);
using var csv = new CsvReader(reader, CsvConfig);
List<CSV.Planet> records = csv.GetRecords<Planet>().ToList();
var planetByPlayer = from csvp in records
group csvp by csvp.Owner into byOwners
@ -90,4 +91,3 @@ public class PlanetLoader
}
}
}
}

View File

@ -85,6 +85,9 @@ public partial class CSVDataLoader : IEnableLogger
case "p":
var loader = new CSV.PlanetLoader();
loader.ImportForRace(Services.Game.Player);
PlanetManager manager = Locator.Current.GetService<PlanetManager>()!;
manager.InitFromDatabase();
break;
default:

View File

@ -123,11 +123,14 @@ public class Game
GameEngine.Game = this;
Locator.CurrentMutable.RegisterConstant(new CSVDataLoader(), typeof(CSVDataLoader));
Locator.CurrentMutable.Register(() => new StarsDatabase(DatabaseFileName), typeof(StarsDatabase));
Locator.CurrentMutable.RegisterConstant(new PlanetManager(), typeof(Services.PlanetManager));
PlanetManager PlanetManager = new();
Locator.CurrentMutable.RegisterConstant(PlanetManager, typeof(Services.PlanetManager));
// TESTING HELPER
if (__doCreateTestData)
__createTestData();
PlanetManager.InitFromDatabase();
}
/// <summary>
@ -163,8 +166,8 @@ public class Game
PRT = PRT.Other,
HasOBRM = true,
FactoryCost3 = false,
FactoryNumberPer10k = 8,
FactoryResCost = 8,
FactoryNumberPer10k = 9,
FactoryResCost = 9,
FactoryResPer10 = 15,
MineResCost = 3,
MineMineralsPer10 = 10,

View File

@ -99,6 +99,13 @@ public class GameEngine
return (int) tmp;
}
/// <summary>
/// Returns the Germanium cost for the given number of factories.
/// </summary>
/// <param name="count">Factory count</param>
/// <returns>Germanium cost</returns>
public static int FactoryGermaniumCostForPlayer(int count) => count * Game.Player.FactoryGerCost;
/// <summary>
/// Returns the maximum operable mines on a given player planet for a given value.
/// </summary>

View File

@ -25,12 +25,12 @@ public class PlanetManager
{
}
public void __test__Init()
public void InitFromDatabase()
{
using var db = Locator.Current.GetService<StarsDatabase>()!;
{
var playerPlanets = db.Planet.ToList();
_planets.AddOrUpdate(playerPlanets);
var allPlanets = db.Planet.ToList();
_planets.AddOrUpdate(allPlanets);
}
}
}

View File

@ -18,7 +18,6 @@ public partial class BuColViewModel : ViewModelBase
public BuColViewModel()
{
var PlanetManager = Locator.Current.GetService<PlanetManager>()!;
PlanetManager.__test__Init();
PlanetManager.PlayerPlanetsSource
.ObserveOn(RxApp.MainThreadScheduler)

View File

@ -30,6 +30,31 @@ public partial class PlayerPlanetViewModel : ViewModelBase
.Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100)
.ToProperty(this, vm => vm.PopulationTarget);
_populationToShipHelper = this
.WhenAnyValue(vm => vm.PopulationTarget)
.Select(popToShip => this.ComputePopulationToShip())
.ToProperty(this, vm => vm.PopulationToShip);
_targetFactoriesHelper = this
.WhenAnyValue(vm => vm.PopulationTarget)
.Select(tgtFact => GameEngine.MaxOperableFactoriesForPlayer(_populationTarget, Value))
.ToProperty(this, vm => vm.TargetFactories);
_remainingFactoriesHelper = this
.WhenAnyValue(vm => vm.TargetFactories)
.Select(factRem => Factories < _targetFactories ? _targetFactories - Factories : 0)
.ToProperty(this, vm => vm.RemainingFactories);
_factoryGermaniumDeltaHelper = this
.WhenAnyValue(vm => vm.RemainingFactories)
.Select(gerCost => ComputeFactoryGermaniumDelta())
.ToProperty(this, vm => vm.FactoryGermaniumDelta);
_remainingMinesHelper = this
.WhenAnyValue(vm => vm.PopulationTarget)
.Select(remMines => Math.Max(0, GameEngine.MaxOperableMinesForPlayer(_populationTarget, Value) - Mines))
.ToProperty(this, vm => vm.RemainingMines);
this.WhenActivated((CompositeDisposable disposables) =>
{
// /* handle activation */
@ -122,6 +147,8 @@ public partial class PlayerPlanetViewModel : ViewModelBase
public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
public int PopulationT1 => Population + PopulationGrowth /* TODO + Pop En Route */;
public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
public int BuildableMines => GameEngine.MaxBuildableMinesForPlayer(Value);
@ -134,9 +161,57 @@ public partial class PlayerPlanetViewModel : ViewModelBase
public int ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value);
public int AvailableIronium => MRIronium + SurfaceIronium;
public int AvailableBoranium => MRBoranium + SurfaceBoranium;
public int AvailableGermanium => MRGermanium + SurfaceGermanium;
[ObservableAsProperty]
private int _populationTarget;
[ObservableAsProperty]
private int _populationToShip;
[ObservableAsProperty]
private int _targetFactories;
[ObservableAsProperty]
private int _remainingFactories;
[ObservableAsProperty]
private int _factoryGermaniumDelta;
[ObservableAsProperty]
private int _remainingMines;
#endregion
#region Helper functions
private int ComputePopulationToShip()
{
if (Population >= _populationTarget)
return Population - _populationTarget;
if (PopulationT1 < _populationTarget)
return PopulationT1 - _populationTarget;
return 0;
}
private int ComputeFactoryGermaniumDelta()
{
int gerReq = GameEngine.FactoryGermaniumCostForPlayer(_remainingFactories);
if (gerReq < AvailableGermanium)
return Math.Max(0, SurfaceGermanium - gerReq);
return AvailableGermanium + MRGermanium - gerReq;
// TODO: Extrapolate to T1, so that excess Germanium is visible.
// TODO: Take shipping into account.
}
#endregion
}

View File

@ -19,7 +19,7 @@
<!-- Class -->
<!-- Info -->
<DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
<!-- Pop To Ship -->
<DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" />
<DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
<!-- Pop en route -->
<DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/>
@ -31,19 +31,20 @@
<!-- Cargo Cap T1 -->
<!-- Cargo Cap T0 -->
<!-- Iro MRE including Shipping -->
<!-- Iro Avl including MRE -->
<DataGridTextColumn Header="Iro Avl" Binding="{Binding AvailableIronium}" />
<!-- Iro Shipping including MRE -->
<!-- Bor MRE including Shipping -->
<!-- Bor Avl including MRE -->
<DataGridTextColumn Header="Bor Avl" Binding="{Binding AvailableBoranium}" />
<!-- Bor Shipping including MRE -->
<!-- Ger MRE including Shipping -->
<!-- Ger Avl including MRE -->
<DataGridTextColumn Header="Ger Avl" Binding="{Binding AvailableGermanium}" />
<!-- Bor Shipping including MRE -->
<!-- Shipbuilding Columns -->
<!-- Factories remaining to pop target -->
<!-- Factories Germanium Delta for target -->
<DataGridTextColumn Header="Fact Rem" Binding="{Binding RemainingFactories}" />
<DataGridTextColumn Header="Fact Tgt" Binding="{Binding TargetFactories}" />
<DataGridTextColumn Header="Fact Ger Delta" Binding="{Binding FactoryGermaniumDelta}" />
<!-- Factory production per turn -->
<!-- Mines remaining to pop target -->
<DataGridTextColumn Header="Mines Rem" Binding="{Binding RemainingMines}" />
<DataGridTextColumn Header="Mines" Binding="{Binding Mines}" />
<DataGridTextColumn Header="Fact" Binding="{Binding Factories}" />
<DataGridTextColumn Header="Res" Binding="{Binding Resources}" />