Skip to content

Commit

Permalink
Added some warnings in the ship designer.
Browse files Browse the repository at this point in the history
  • Loading branch information
se5a committed Dec 13, 2024
1 parent fa44de1 commit 52899e8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Pulsar4X/GameEngine/Storage/StorageSpaceProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ internal static (int rate, double range) CalcRateAndRange(ComponentInstancesDB i
}
}
}
int finalRate = (int)(rate / i);
int finalRate = (int)rate;
double finalRange = range / i;
return (finalRate, finalRange);
}

internal static Dictionary<string, double> CalculatedMaxStorage(ShipDesign shipDesign)
public static Dictionary<string, double> CalculatedMaxStorage(ShipDesign shipDesign)
{
Dictionary<string, double> calculatedMaxStorage = new ();
foreach (var component in shipDesign.Components)
Expand All @@ -102,7 +102,7 @@ internal static Dictionary<string, double> CalculatedMaxStorage(ShipDesign shipD
return calculatedMaxStorage;
}

internal static (int rate, double range) CalcRateAndRange(ShipDesign shipDesign)
public static (int rate, double range) CalcRateAndRange(ShipDesign shipDesign)
{
double rate = 0;
double range = 0;
Expand All @@ -112,12 +112,12 @@ internal static (int rate, double range) CalcRateAndRange(ShipDesign shipDesign)
if (component.design.HasAttribute<CargoTransferAtb>())
{
var atbdata = component.design.GetAttribute<CargoTransferAtb>();
rate += atbdata.TransferRate_kgs;
rate += atbdata.TransferRate_kgs * component.count;
range += atbdata.TransferRange_ms;
i++;
}
}
int finalRate = (int)(rate / i);
int finalRate = (int)rate;
double finalRange = range / i;
return (finalRate, finalRange);
}
Expand Down
43 changes: 38 additions & 5 deletions Pulsar4X/Pulsar4X.Client/Interface/Windows/ShipDesignWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using Pulsar4X.Storage;
using Pulsar4X.Movement;
using Pulsar4X.Names;
using SDL2;

namespace Pulsar4X.SDL2UI
{
Expand Down Expand Up @@ -703,6 +704,11 @@ internal void DisplayStats()
ImGui.PopStyleColor();
}

foreach (var warning in Warnings())
{
ImGui.Text(warning);
}

ImGui.NewLine();
NewShipButton();
ImGui.SameLine();
Expand Down Expand Up @@ -780,6 +786,7 @@ private void UpdateShipStats()
estor += atb.MaxStore * component.count;
}

/*
if (component.design.HasAttribute<CargoStorageAtb>())
{
var atb = component.design.GetAttribute<CargoStorageAtb>();
Expand All @@ -795,9 +802,20 @@ private void UpdateShipStats()
{
var atb = component.design.GetAttribute<CargoTransferAtb>();
//atb.TransferRange_ms
}
}*/
}

cstore = StorageSpaceProcessor.CalculatedMaxStorage(_workingDesign);
var cargoTransfer = StorageSpaceProcessor.CalcRateAndRange(_workingDesign);
foreach (var store in cstore)
{
if (store.Key != thrusterFuel)
_cvol += store.Value;
}



_armorMass = ShipDesign.GetArmorMass(_profile, _uiState.Faction.GetDataBlob<FactionInfoDB>().Data.CargoGoods);
mass += (long)Math.Round(_armorMass);

Expand All @@ -813,6 +831,8 @@ private void UpdateShipStats()
_wspd = WarpMath.MaxSpeedCalc(wp, mass);
_egen = egen;
_estor = estor;
_trate = cargoTransfer.rate;
_trnge = cargoTransfer.range;
//double fuelMass = 0;
if (thrusterFuel.IsNotNullOrEmpty())
{
Expand Down Expand Up @@ -883,11 +903,24 @@ internal void DisplayImage(float maxwidth, float maxheight)
ImGui.Image(_shipImgPtr, new System.Numerics.Vector2(rawimagewidth * scale, rawimageheight * scale));
}
}

private List<string> _warningString = new List<string>();
private void Warnings()

private List<string> Warnings()
{
//if(_workingDesign.Components.)
List<string> warnings = new List<string>();
if (_cvol > 0 && _trate == 0 || _trnge == 0)
{
warnings.Add("This ship has cargo space but no way to transfer cargo by itself");
}
if (_wspd == 0)
{
warnings.Add("This ship has no warp ability");
}

if (_ttwr == 0)
{
warnings.Add("This ship has no newtonion thrust");
}
return warnings;
}
}
}

0 comments on commit 52899e8

Please sign in to comment.