BuCol Setup
This commit is contained in:
parent
a394918064
commit
a03edf8983
@ -4,6 +4,7 @@ using CsvHelper.Configuration;
|
|||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using Splat;
|
using Splat;
|
||||||
|
using StarsAssistant.Services;
|
||||||
|
|
||||||
namespace StarsAssistant.CSV;
|
namespace StarsAssistant.CSV;
|
||||||
|
|
||||||
@ -45,49 +46,48 @@ public class PlanetLoader
|
|||||||
/// <param name="race">Import File</param>
|
/// <param name="race">Import File</param>
|
||||||
public void ImportForRace(Model.Race race)
|
public void ImportForRace(Model.Race race)
|
||||||
{
|
{
|
||||||
using (var db = Locator.Current.GetService<Model.StarsDatabase>()!)
|
using var db = Locator.Current.GetService<Model.StarsDatabase>()!;
|
||||||
using (var reader = new StreamReader(Game.PlanetFileForRace(race), System.Text.Encoding.Latin1))
|
using var reader = new StreamReader(Game.PlanetFileForRace(race), System.Text.Encoding.Latin1);
|
||||||
using (var csv = new CsvReader(reader, CsvConfig))
|
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
|
|
||||||
select byOwners;
|
|
||||||
|
|
||||||
foreach (var owner in planetByPlayer)
|
List<CSV.Planet> records = csv.GetRecords<Planet>().ToList();
|
||||||
|
var planetByPlayer = from csvp in records
|
||||||
|
group csvp by csvp.Owner into byOwners
|
||||||
|
select byOwners;
|
||||||
|
|
||||||
|
foreach (var owner in planetByPlayer)
|
||||||
|
{
|
||||||
|
Model.Race? r;
|
||||||
|
if (owner.Key == race.Name)
|
||||||
{
|
{
|
||||||
Model.Race? r;
|
r = race;
|
||||||
if (owner.Key == race.Name)
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r = db.Race.Find(owner.Key);
|
||||||
|
if (r == null)
|
||||||
{
|
{
|
||||||
r = race;
|
r = new() { Name = owner.Key };
|
||||||
|
db.Add(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (Planet csvp in owner)
|
||||||
|
{
|
||||||
|
Model.Planet? p = db.Planet.Find(csvp.Name);
|
||||||
|
if (p == null)
|
||||||
|
{
|
||||||
|
p = new() { Name = csvp.Name };
|
||||||
|
csvp.UpdateDbPlanet(p);
|
||||||
|
db.Add(p);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
r = db.Race.Find(owner.Key);
|
csvp.UpdateDbPlanet(p);
|
||||||
if (r == null)
|
db.Update(p);
|
||||||
{
|
|
||||||
r = new() { Name = owner.Key };
|
|
||||||
db.Add(r);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Planet csvp in owner)
|
|
||||||
{
|
|
||||||
Model.Planet? p = db.Planet.Find(csvp.Name);
|
|
||||||
if (p == null)
|
|
||||||
{
|
|
||||||
p = new() { Name = csvp.Name };
|
|
||||||
csvp.UpdateDbPlanet(p);
|
|
||||||
db.Add(p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
csvp.UpdateDbPlanet(p);
|
|
||||||
db.Update(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.SaveChanges();
|
|
||||||
}
|
}
|
||||||
|
db.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +85,9 @@ public partial class CSVDataLoader : IEnableLogger
|
|||||||
case "p":
|
case "p":
|
||||||
var loader = new CSV.PlanetLoader();
|
var loader = new CSV.PlanetLoader();
|
||||||
loader.ImportForRace(Services.Game.Player);
|
loader.ImportForRace(Services.Game.Player);
|
||||||
|
|
||||||
|
PlanetManager manager = Locator.Current.GetService<PlanetManager>()!;
|
||||||
|
manager.InitFromDatabase();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -123,11 +123,14 @@ public class Game
|
|||||||
GameEngine.Game = this;
|
GameEngine.Game = this;
|
||||||
Locator.CurrentMutable.RegisterConstant(new CSVDataLoader(), typeof(CSVDataLoader));
|
Locator.CurrentMutable.RegisterConstant(new CSVDataLoader(), typeof(CSVDataLoader));
|
||||||
Locator.CurrentMutable.Register(() => new StarsDatabase(DatabaseFileName), typeof(StarsDatabase));
|
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
|
// TESTING HELPER
|
||||||
if (__doCreateTestData)
|
if (__doCreateTestData)
|
||||||
__createTestData();
|
__createTestData();
|
||||||
|
|
||||||
|
PlanetManager.InitFromDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -163,8 +166,8 @@ public class Game
|
|||||||
PRT = PRT.Other,
|
PRT = PRT.Other,
|
||||||
HasOBRM = true,
|
HasOBRM = true,
|
||||||
FactoryCost3 = false,
|
FactoryCost3 = false,
|
||||||
FactoryNumberPer10k = 8,
|
FactoryNumberPer10k = 9,
|
||||||
FactoryResCost = 8,
|
FactoryResCost = 9,
|
||||||
FactoryResPer10 = 15,
|
FactoryResPer10 = 15,
|
||||||
MineResCost = 3,
|
MineResCost = 3,
|
||||||
MineMineralsPer10 = 10,
|
MineMineralsPer10 = 10,
|
||||||
|
@ -99,6 +99,13 @@ public class GameEngine
|
|||||||
return (int) tmp;
|
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>
|
/// <summary>
|
||||||
/// Returns the maximum operable mines on a given player planet for a given value.
|
/// Returns the maximum operable mines on a given player planet for a given value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -25,12 +25,12 @@ public class PlanetManager
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void __test__Init()
|
public void InitFromDatabase()
|
||||||
{
|
{
|
||||||
using var db = Locator.Current.GetService<StarsDatabase>()!;
|
using var db = Locator.Current.GetService<StarsDatabase>()!;
|
||||||
{
|
{
|
||||||
var playerPlanets = db.Planet.ToList();
|
var allPlanets = db.Planet.ToList();
|
||||||
_planets.AddOrUpdate(playerPlanets);
|
_planets.AddOrUpdate(allPlanets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ public partial class BuColViewModel : ViewModelBase
|
|||||||
public BuColViewModel()
|
public BuColViewModel()
|
||||||
{
|
{
|
||||||
var PlanetManager = Locator.Current.GetService<PlanetManager>()!;
|
var PlanetManager = Locator.Current.GetService<PlanetManager>()!;
|
||||||
PlanetManager.__test__Init();
|
|
||||||
|
|
||||||
PlanetManager.PlayerPlanetsSource
|
PlanetManager.PlayerPlanetsSource
|
||||||
.ObserveOn(RxApp.MainThreadScheduler)
|
.ObserveOn(RxApp.MainThreadScheduler)
|
||||||
|
@ -30,6 +30,31 @@ public partial class PlayerPlanetViewModel : ViewModelBase
|
|||||||
.Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100)
|
.Select(popTgt => this.MaxPopulation * popTgt / 10000 * 100)
|
||||||
.ToProperty(this, vm => vm.PopulationTarget);
|
.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) =>
|
this.WhenActivated((CompositeDisposable disposables) =>
|
||||||
{
|
{
|
||||||
// /* handle activation */
|
// /* handle activation */
|
||||||
@ -122,6 +147,8 @@ public partial class PlayerPlanetViewModel : ViewModelBase
|
|||||||
|
|
||||||
public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
|
public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
|
||||||
|
|
||||||
|
public int PopulationT1 => Population + PopulationGrowth /* TODO + Pop En Route */;
|
||||||
|
|
||||||
public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
|
public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
|
||||||
|
|
||||||
public int BuildableMines => GameEngine.MaxBuildableMinesForPlayer(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 ResourcesFromFactories => GameEngine.ResourcesFromFactForPlayer(Population, Factories, Value);
|
||||||
|
|
||||||
|
public int AvailableIronium => MRIronium + SurfaceIronium;
|
||||||
|
|
||||||
|
public int AvailableBoranium => MRBoranium + SurfaceBoranium;
|
||||||
|
|
||||||
|
public int AvailableGermanium => MRGermanium + SurfaceGermanium;
|
||||||
|
|
||||||
[ObservableAsProperty]
|
[ObservableAsProperty]
|
||||||
private int _populationTarget;
|
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
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
@ -19,7 +19,7 @@
|
|||||||
<!-- Class -->
|
<!-- Class -->
|
||||||
<!-- Info -->
|
<!-- Info -->
|
||||||
<DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
|
<DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
|
||||||
<!-- Pop To Ship -->
|
<DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" />
|
||||||
<DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
|
<DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
|
||||||
<!-- Pop en route -->
|
<!-- Pop en route -->
|
||||||
<DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/>
|
<DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/>
|
||||||
@ -31,19 +31,20 @@
|
|||||||
<!-- Cargo Cap T1 -->
|
<!-- Cargo Cap T1 -->
|
||||||
<!-- Cargo Cap T0 -->
|
<!-- Cargo Cap T0 -->
|
||||||
<!-- Iro MRE including Shipping -->
|
<!-- Iro MRE including Shipping -->
|
||||||
<!-- Iro Avl including MRE -->
|
<DataGridTextColumn Header="Iro Avl" Binding="{Binding AvailableIronium}" />
|
||||||
<!-- Iro Shipping including MRE -->
|
<!-- Iro Shipping including MRE -->
|
||||||
<!-- Bor MRE including Shipping -->
|
<!-- Bor MRE including Shipping -->
|
||||||
<!-- Bor Avl including MRE -->
|
<DataGridTextColumn Header="Bor Avl" Binding="{Binding AvailableBoranium}" />
|
||||||
<!-- Bor Shipping including MRE -->
|
<!-- Bor Shipping including MRE -->
|
||||||
<!-- Ger MRE including Shipping -->
|
<!-- Ger MRE including Shipping -->
|
||||||
<!-- Ger Avl including MRE -->
|
<DataGridTextColumn Header="Ger Avl" Binding="{Binding AvailableGermanium}" />
|
||||||
<!-- Bor Shipping including MRE -->
|
<!-- Bor Shipping including MRE -->
|
||||||
<!-- Shipbuilding Columns -->
|
<!-- Shipbuilding Columns -->
|
||||||
<!-- Factories remaining to pop target -->
|
<DataGridTextColumn Header="Fact Rem" Binding="{Binding RemainingFactories}" />
|
||||||
<!-- Factories Germanium Delta for target -->
|
<DataGridTextColumn Header="Fact Tgt" Binding="{Binding TargetFactories}" />
|
||||||
|
<DataGridTextColumn Header="Fact Ger Delta" Binding="{Binding FactoryGermaniumDelta}" />
|
||||||
<!-- Factory production per turn -->
|
<!-- Factory production per turn -->
|
||||||
<!-- Mines remaining to pop target -->
|
<DataGridTextColumn Header="Mines Rem" Binding="{Binding RemainingMines}" />
|
||||||
<DataGridTextColumn Header="Mines" Binding="{Binding Mines}" />
|
<DataGridTextColumn Header="Mines" Binding="{Binding Mines}" />
|
||||||
<DataGridTextColumn Header="Fact" Binding="{Binding Factories}" />
|
<DataGridTextColumn Header="Fact" Binding="{Binding Factories}" />
|
||||||
<DataGridTextColumn Header="Res" Binding="{Binding Resources}" />
|
<DataGridTextColumn Header="Res" Binding="{Binding Resources}" />
|
||||||
|
Loading…
Reference in New Issue
Block a user