Intermediate fleet summaries attempt
This commit is contained in:
parent
1bee62173c
commit
e79a308243
@ -37,84 +37,11 @@ public class FleetManager : IEnableLogger, IDisposable
|
||||
public IObservableCache<FleetSummaryByDestination, string> FleetSummariesByDestination
|
||||
=> _fleetSummariesByDestination.AsObservableCache();
|
||||
|
||||
/// <summary>
|
||||
/// Public accessor to the continously updated fleet summaries.
|
||||
/// </summary>
|
||||
// public IObservableCache<FleetSummaryByDestination, string> FleetSummariesByDestination => _fleetSummaries.AsObservableCache();
|
||||
|
||||
/// <summary>
|
||||
/// Disposal tracking
|
||||
/// </summary>
|
||||
// private IDisposable _fleetSummariesSubscription;
|
||||
|
||||
public FleetManager()
|
||||
{
|
||||
// CreateFleetSummariesLink();
|
||||
}
|
||||
|
||||
// [MemberNotNull(nameof(_fleetSummariesSubscription))]
|
||||
// protected void CreateFleetSummariesLink()
|
||||
// {
|
||||
// /*
|
||||
// _fleetSummariesSubscription = _fleets.Connect()
|
||||
// .Filter(fleet => fleet.TrueDestination != "-- ")
|
||||
// .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher filter", fleet => $"{fleet}")
|
||||
// // .AutoRefreshOnObservable(fleet => fleet.WhenAnyValue(
|
||||
// // f => f.Ironium, f => f.Boranium, f => f.Germanium, f => f.Colonists))
|
||||
// .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher refresh", fleet => $"{fleet}")
|
||||
// .GroupOn(fleet => fleet.TrueDestination)
|
||||
// .Log(this, $"{DateTime.Now.ToLongTimeString()} fleetWatcher group", grp => $"{grp.TotalChanges} detected")
|
||||
// .Transform(group => new FleetSummaryByDestination
|
||||
// {
|
||||
// Destination = group.GroupKey,
|
||||
// TotalIronium = group.List.Items.Sum(f => f.Ironium),
|
||||
// TotalBoranium = group.List.Items.Sum(f => f.Boranium),
|
||||
// TotalGermanium = group.List.Items.Sum(f => f.Germanium),
|
||||
// TotalColonists = group.List.Items.Sum(f => f.Colonists)
|
||||
// })
|
||||
|
||||
// .AddKey(fs => fs.Destination)
|
||||
// .Log(this, "FleetManager _fleetSummaries update", changes =>
|
||||
// $"{changes.Adds} adds, {changes.Updates} updates, {changes.Removes} removes"
|
||||
// )
|
||||
// .PopulateInto(_fleetSummaries)
|
||||
// ;
|
||||
// */
|
||||
|
||||
// /*
|
||||
// // Demo only
|
||||
// var sourceCache = new SourceCache<FleetSummaryByDestination, string>(fs => fs.Destination);
|
||||
// var tmp = fleetSummaries
|
||||
// .AddKey(fs => fs.Destination)
|
||||
// .PopulateInto(sourceCache);
|
||||
|
||||
// _fleetSummaries
|
||||
// .ObserveOn(RxApp.MainThreadScheduler)
|
||||
// .Bind(out summaries)
|
||||
// .DisposeMany()
|
||||
// .Subscribe();
|
||||
|
||||
// d1 = summaries
|
||||
// .Subscribe(Observer.Create<FleetSummaryByDestination>(f =>
|
||||
// {
|
||||
// this.Log().Debug($"FleetSummaryByDestination observed: {f}");
|
||||
// }
|
||||
// ));
|
||||
|
||||
// d2 = _fleetSummaries
|
||||
// .ObserveOn(RxApp.MainThreadScheduler)
|
||||
// .Subscribe(x =>
|
||||
// {
|
||||
// var lst = x.ToList();
|
||||
// foreach (var f in lst)
|
||||
// {
|
||||
// this.Log().Debug($"Reason {f.Reason}, Type {f.Type}: {f.Item.Current}");
|
||||
// }
|
||||
// }
|
||||
// );
|
||||
// */
|
||||
// }
|
||||
|
||||
/// <summary>
|
||||
/// Load the fleet records from the database and push them into our source cache.
|
||||
/// If the data has been freshly imported, call PostProcessImportedData first.
|
||||
@ -201,7 +128,6 @@ public class FleetManager : IEnableLogger, IDisposable
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
// _fleetSummariesSubscription.Dispose();
|
||||
_fleetSummariesByDestination.Dispose();
|
||||
_fleets.Dispose();
|
||||
}
|
||||
|
@ -50,7 +50,10 @@ public partial class PlayerPlanetViewModel : ViewModelBase
|
||||
.ToProperty(this, vm => vm.RemainingFactories);
|
||||
|
||||
_factoryGermaniumDeltaHelper = this
|
||||
.WhenAnyValue(vm => vm.RemainingFactories)
|
||||
.WhenAnyValue(vm => vm.RemainingFactories,
|
||||
vm => vm.EnRouteGermanium,
|
||||
vm => vm.SurfaceGermanium,
|
||||
(remFact, gerEnRoute, surGer) => remFact)
|
||||
.Select(gerCost => ComputeFactoryGermaniumDelta())
|
||||
.ToProperty(this, vm => vm.FactoryGermaniumDelta);
|
||||
|
||||
@ -67,15 +70,36 @@ public partial class PlayerPlanetViewModel : ViewModelBase
|
||||
.Log(this, "fleetSummaryChange", change => $"{Name}: {change.Reason}: {change.Previous} => {change.Current}")
|
||||
;
|
||||
|
||||
_populationEnRouteHelper = _fleetSummaryChanges
|
||||
_enRoutePopulationHelper = _fleetSummaryChanges
|
||||
.Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalColonists : 0)
|
||||
.Log(this, "PopulationEnRoute", pop => $"{Name}: {pop}")
|
||||
.ToProperty(this, vm => vm.PopulationEnRoute)
|
||||
.Log(this, "EnRoutePopulation", pop => $"{Name}: {pop}")
|
||||
.ToProperty(this, vm => vm.EnRoutePopulation)
|
||||
;
|
||||
|
||||
_enRouteIroniumHelper = _fleetSummaryChanges
|
||||
.Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalIronium : 0)
|
||||
.Log(this, "EnRouteIronium", ironium => $"{Name}: {ironium}")
|
||||
.ToProperty(this, vm => vm.EnRouteIronium)
|
||||
;
|
||||
|
||||
_enRouteBoraniumHelper = _fleetSummaryChanges
|
||||
.Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalBoranium : 0)
|
||||
.Log(this, "EnRouteBoranium", boranium => $"{Name}: {boranium}")
|
||||
.ToProperty(this, vm => vm.EnRouteBoranium)
|
||||
;
|
||||
|
||||
_enRouteGermaniumHelper = _fleetSummaryChanges
|
||||
.Select(change => change.Reason != ChangeReason.Remove ? change.Current.TotalGermanium : 0)
|
||||
.Log(this, "EnRouteGermanium", germanium => $"{Name}: {germanium}")
|
||||
.ToProperty(this, vm => vm.EnRouteGermanium)
|
||||
;
|
||||
|
||||
this.WhenActivated((CompositeDisposable disposables) =>
|
||||
{
|
||||
disposables.Add(_populationEnRouteHelper);
|
||||
disposables.Add(_enRoutePopulationHelper);
|
||||
disposables.Add(_enRouteIroniumHelper);
|
||||
disposables.Add(_enRouteBoraniumHelper);
|
||||
disposables.Add(_enRouteGermaniumHelper);
|
||||
|
||||
// /* handle activation */
|
||||
// Disposable
|
||||
@ -167,7 +191,7 @@ public partial class PlayerPlanetViewModel : ViewModelBase
|
||||
|
||||
public int PopulationGrowth => GameEngine.PlanetPopGrowthForPlayer(Population, Value);
|
||||
|
||||
public int PopulationT1 => Population + PopulationGrowth /* TODO + Pop En Route */;
|
||||
public int PopulationT1 => Population + PopulationGrowth + EnRoutePopulation;
|
||||
|
||||
public int BuildableFactories => GameEngine.MaxBuildableFactoriesForPlayer(Value);
|
||||
|
||||
@ -187,27 +211,26 @@ public partial class PlayerPlanetViewModel : ViewModelBase
|
||||
|
||||
public int AvailableGermanium => MRGermanium + SurfaceGermanium;
|
||||
|
||||
[ObservableAsProperty]
|
||||
private int _populationTarget;
|
||||
[ObservableAsProperty] private int _populationTarget;
|
||||
|
||||
[ObservableAsProperty]
|
||||
private int _populationToShip;
|
||||
[ObservableAsProperty] private int _populationToShip;
|
||||
|
||||
[ObservableAsProperty]
|
||||
private int _targetFactories;
|
||||
[ObservableAsProperty] private int _targetFactories;
|
||||
|
||||
[ObservableAsProperty]
|
||||
private int _remainingFactories;
|
||||
[ObservableAsProperty] private int _remainingFactories;
|
||||
|
||||
[ObservableAsProperty]
|
||||
private int _factoryGermaniumDelta;
|
||||
[ObservableAsProperty] private int _factoryGermaniumDelta;
|
||||
|
||||
[ObservableAsProperty]
|
||||
private int _remainingMines;
|
||||
[ObservableAsProperty] private int _remainingMines;
|
||||
|
||||
[ObservableAsProperty]
|
||||
private int _populationEnRoute;
|
||||
[ObservableAsProperty] private int _enRoutePopulation;
|
||||
|
||||
[ObservableAsProperty] private int _enRouteIronium;
|
||||
|
||||
[ObservableAsProperty] private int _enRouteBoranium;
|
||||
|
||||
[ObservableAsProperty] private int _enRouteGermanium;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper functions
|
||||
@ -230,24 +253,19 @@ public partial class PlayerPlanetViewModel : ViewModelBase
|
||||
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.
|
||||
// When extrapolating to T1, we take the available Germanium
|
||||
// this turn (surface + MR), add MR a second time (the mines
|
||||
// will yield it next turn as well) and add the inbound shipping
|
||||
// as this will be available next turn as well. That#s the basis
|
||||
// for the Germanium requirement in the next turn. We will top
|
||||
// it out at 0, as we don't have any Germanium available this
|
||||
// turn, and we don't want to show a projected surplus here
|
||||
// (we can't pull it off the planet in this turn anyway).
|
||||
return Math.Min(
|
||||
AvailableGermanium + EnRouteGermanium + MRGermanium - gerReq
|
||||
, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
private int ComputePopulationEnRoute()
|
||||
{
|
||||
using var db = Locator.Current.GetService<Model.StarsDatabase>()!;
|
||||
|
||||
var enRoute = from flt in db.Fleet
|
||||
where flt.OwnerFileId == Game.Player.PlayerFileId && flt.TrueDestination == Planet.Name
|
||||
select new { Colonists = flt.Sum(f => f.Colonists) };
|
||||
|
||||
return enRoute.Colonists ?? 0;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
@ -21,7 +21,7 @@
|
||||
<DataGridTextColumn Header="Pop" Binding="{Binding Population}" />
|
||||
<DataGridTextColumn Header="Pop to Ship" Binding="{Binding PopulationToShip}" />
|
||||
<DataGridTextColumn Header="Growth" Binding="{Binding PopulationGrowth}" />
|
||||
<DataGridTextColumn Header="Pop T1" Binding="{Binding PopulationEnRoute}" />
|
||||
<DataGridTextColumn Header="Pop T1" Binding="{Binding EnRoutePopulation}" />
|
||||
<DataGridTextColumn Header="Pop T%" Binding="{Binding PopulationTargetPercent}" IsReadOnly="false"/>
|
||||
<DataGridTextColumn Header="Pop %" Binding="{Binding CapacityPercent}" />
|
||||
<!-- Terra Delta assumed -->
|
||||
@ -31,13 +31,19 @@
|
||||
<!-- Cargo Cap T1 -->
|
||||
<!-- Cargo Cap T0 -->
|
||||
<!-- Iro MRE including Shipping -->
|
||||
<DataGridTextColumn Header="Iro Sur" Binding="{Binding SurfaceIronium}" />
|
||||
<DataGridTextColumn Header="Iro Avl" Binding="{Binding AvailableIronium}" />
|
||||
<DataGridTextColumn Header="Iro Trn" Binding="{Binding EnRouteIronium}" />
|
||||
<!-- Iro Shipping including MRE -->
|
||||
<!-- Bor MRE including Shipping -->
|
||||
<DataGridTextColumn Header="Bor Sur" Binding="{Binding SurfaceBoranium}" />
|
||||
<DataGridTextColumn Header="Bor Avl" Binding="{Binding AvailableBoranium}" />
|
||||
<DataGridTextColumn Header="Bor Trn" Binding="{Binding EnRouteBoranium}" />
|
||||
<!-- Bor Shipping including MRE -->
|
||||
<!-- Ger MRE including Shipping -->
|
||||
<DataGridTextColumn Header="Ger Sur" Binding="{Binding SurfaceGermanium}" />
|
||||
<DataGridTextColumn Header="Ger Avl" Binding="{Binding AvailableGermanium}" />
|
||||
<DataGridTextColumn Header="Ger Trn" Binding="{Binding EnRouteGermanium}" />
|
||||
<!-- Bor Shipping including MRE -->
|
||||
<!-- Shipbuilding Columns -->
|
||||
<DataGridTextColumn Header="Fact Rem" Binding="{Binding RemainingFactories}" />
|
||||
|
Loading…
Reference in New Issue
Block a user