Skip to content

Commit

Permalink
Partially revert df4edff
Browse files Browse the repository at this point in the history
VoiceAttack needs decimal values rather than doubles.
Revise jump calcs to exclude aux fuel reservoir.
  • Loading branch information
Tkael authored and bcthund committed Jun 26, 2024
1 parent f5294ce commit d58ade5
Show file tree
Hide file tree
Showing 28 changed files with 224 additions and 351 deletions.
4 changes: 2 additions & 2 deletions DataDefinitions/JumpDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace EddiDataDefinitions
public class JumpDetail
{
[PublicAPI]
public double distance { get; private set; }
public decimal distance { get; private set; }

[PublicAPI]
public int jumps { get; private set; }

public JumpDetail() { }

public JumpDetail(double distance, int jumps)
public JumpDetail(decimal distance, int jumps)
{
this.distance = distance;
this.jumps = jumps;
Expand Down
40 changes: 20 additions & 20 deletions DataDefinitions/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public double GetFsdRatingConstant ()
}
}

public double GetFsdMaxFuelPerJump ()
public decimal GetFsdMaxFuelPerJump ()
{
if ( string.IsNullOrEmpty( grade ) || @class == 0 ) { return 0; }

Expand All @@ -233,35 +233,35 @@ public double GetFsdMaxFuelPerJump ()
m.EDName.Equals("MaxFuelPerJump", StringComparison.InvariantCultureIgnoreCase))?.currentValue;
if ( maxFuelPerJump != null )
{
return (double) maxFuelPerJump;
return (decimal) maxFuelPerJump;
}

// No modified value exists, use a base value
double baseMaxFuelPerJump;
decimal baseMaxFuelPerJump;
if ( edname?.Contains( "hyperdrive_overcharge" ) ?? false )
{
var baseMaxFuelsPerJump_SCO = new Dictionary<string, double>
var baseMaxFuelsPerJump_SCO = new Dictionary<string, decimal>
{
{ "2E", 0.60 }, { "2D", 0.90 }, { "2C", 0.90 }, { "2B", 0.90 }, { "2A", 1.00 },
{ "3E", 1.20 }, { "3D", 1.80 }, { "3C", 1.80 }, { "3B", 1.80 }, { "3A", 1.90 },
{ "4E", 2.00 }, { "4D", 3.00 }, { "4C", 3.00 }, { "4B", 3.00 }, { "4A", 3.20 },
{ "5E", 3.30 }, { "5D", 5.00 }, { "5C", 5.00 }, { "5B", 5.00 }, { "5A", 5.20 },
{ "6E", 5.30 }, { "6D", 8.00 }, { "6C", 8.00 }, { "6B", 8.00 }, { "6A", 8.30 },
{ "7E", 8.50 }, { "7D", 12.8 }, { "7C", 12.8 }, { "7B", 12.8 }, { "7A", 13.1 }
{ "2E", 0.60M }, { "2D", 0.90M }, { "2C", 0.90M }, { "2B", 0.90M }, { "2A", 1.00M },
{ "3E", 1.20M }, { "3D", 1.80M }, { "3C", 1.80M }, { "3B", 1.80M }, { "3A", 1.90M },
{ "4E", 2.00M }, { "4D", 3.00M }, { "4C", 3.00M }, { "4B", 3.00M }, { "4A", 3.20M },
{ "5E", 3.30M }, { "5D", 5.00M }, { "5C", 5.00M }, { "5B", 5.00M }, { "5A", 5.20M },
{ "6E", 5.30M }, { "6D", 8.00M }, { "6C", 8.00M }, { "6B", 8.00M }, { "6A", 8.30M },
{ "7E", 8.50M }, { "7D", 12.8M }, { "7C", 12.8M }, { "7B", 12.8M }, { "7A", 13.1M }
};
baseMaxFuelsPerJump_SCO.TryGetValue( @class + grade, out baseMaxFuelPerJump );
}
else
{
var baseMaxFuelsPerJump = new Dictionary<string, double>
var baseMaxFuelsPerJump = new Dictionary<string, decimal>
{
{ "2E", 0.60 }, { "2D", 0.60 }, { "2C", 0.60 }, { "2B", 0.80 }, { "2A", 0.90 },
{ "3E", 1.20 }, { "3D", 1.20 }, { "3C", 1.20 }, { "3B", 1.50 }, { "3A", 1.80 },
{ "4E", 2.00 }, { "4D", 2.00 }, { "4C", 2.00 }, { "4B", 2.50 }, { "4A", 3.00 },
{ "5E", 3.30 }, { "5D", 3.30 }, { "5C", 3.30 }, { "5B", 4.10 }, { "5A", 5.00 },
{ "6E", 5.30 }, { "6D", 5.30 }, { "6C", 5.30 }, { "6B", 6.60 }, { "6A", 8.00 },
{ "7E", 8.50 }, { "7D", 8.50 }, { "7C", 8.50 }, { "7B", 10.6 }, { "7A", 12.8 },
{ "8E", 13.6 }, { "8D", 13.6 }, { "8C", 13.6 }, { "8B", 17.0 }, { "8A", 20.4 }
{ "2E", 0.60M }, { "2D", 0.60M }, { "2C", 0.60M }, { "2B", 0.80M }, { "2A", 0.90M },
{ "3E", 1.20M }, { "3D", 1.20M }, { "3C", 1.20M }, { "3B", 1.50M }, { "3A", 1.80M },
{ "4E", 2.00M }, { "4D", 2.00M }, { "4C", 2.00M }, { "4B", 2.50M }, { "4A", 3.00M },
{ "5E", 3.30M }, { "5D", 3.30M }, { "5C", 3.30M }, { "5B", 4.10M }, { "5A", 5.00M },
{ "6E", 5.30M }, { "6D", 5.30M }, { "6C", 5.30M }, { "6B", 6.60M }, { "6A", 8.00M },
{ "7E", 8.50M }, { "7D", 8.50M }, { "7C", 8.50M }, { "7B", 10.6M }, { "7A", 12.8M },
{ "8E", 13.6M }, { "8D", 13.6M }, { "8C", 13.6M }, { "8B", 17.0M }, { "8A", 20.4M }
};
baseMaxFuelsPerJump.TryGetValue( @class + grade, out baseMaxFuelPerJump );
}
Expand Down Expand Up @@ -335,8 +335,8 @@ public double GetGuardianFSDBoost ()
public class EngineeringModifier
{
public string EDName { get; set; }
public double? currentValue { get; set; }
public double? originalValue { get; set; }
public decimal? currentValue { get; set; }
public decimal? originalValue { get; set; }
public bool lessIsGood { get; set; }
public string valueStr { get; set; }
}
Expand Down
107 changes: 38 additions & 69 deletions DataDefinitions/Ship.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ public class Ship : INotifyPropertyChanged
public int? militarysize { get; set; }

/// <summary>the total tonnage cargo capacity</summary>
[PublicAPI]
public int cargocapacity { get; set; }
[ PublicAPI, JsonIgnore]
public int cargocapacity => compartments
.Where( c=> c.module != null )
.Select(c => c.module)
.Where( m => m.@class > 0 && m.basename.Contains( "CargoRack", StringComparison.InvariantCultureIgnoreCase ))
.Sum( m => 1 << m.@class); // Calculated using a shift operator (`<<`), equiv to 2^(@class), calculated as an integer )

/// <summary>the value of the ship without cargo, in credits</summary>

Expand Down Expand Up @@ -401,8 +405,6 @@ public Module frameshiftdrive
set
{
_frameshiftdrive = value;
maxfuelperjump = value?.GetFsdMaxFuelPerJump() ?? 0;
optimalmass = value?.GetFsdOptimalMass() ?? 0;
OnPropertyChanged();
}
}
Expand Down Expand Up @@ -437,7 +439,7 @@ public Module fueltank
{
get => _fueltank;
set { _fueltank = value; OnPropertyChanged(); }
}
}
private Module _fueltank = new Module();

[PublicAPI, JetBrains.Annotations.NotNull, JetBrains.Annotations.ItemNotNull]
Expand Down Expand Up @@ -466,28 +468,22 @@ public List<LaunchBay> launchbays

public string paintjob { get; set; }

[PublicAPI]
public double? fueltankcapacity // Core capacity
{
get => _fueltankcapacity;
set { _fueltankcapacity = value ?? 0; OnPropertyChanged(); }
}
private double _fueltankcapacity;
[PublicAPI, JsonIgnore] // Core capacity
public decimal? fueltankcapacity => fueltank?.@class > 0 ? 1 << fueltank?.@class : 0; // Shift operator, equiv to 2^(fueltank.@class), calculated as an integer

[PublicAPI]
public double? fueltanktotalcapacity // Capacity including additional tanks
{
get => _fueltanktotalcapacity;
set { _fueltanktotalcapacity = value ?? 0; OnPropertyChanged(); }
}
private double _fueltanktotalcapacity;
[PublicAPI, JsonIgnore] // Capacity including additional tanks (and excluding the active fuel reservoir)
public decimal? fueltanktotalcapacity => fueltankcapacity + compartments
.Where( c => c.module != null )
.Select( c => c.module )
.Where( m => m.@class > 0 && m.basename.Contains( "FuelTank", StringComparison.InvariantCultureIgnoreCase ) )
.Sum( m => 1 << m.@class ); // Calculated using a shift operator (`<<`), equiv to 2^(@class), calculated as an integer )

public double activeFuelReservoirCapacity { get; set; }
public decimal activeFuelReservoirCapacity { get; set; }

// Ship jump and mass properties

[PublicAPI]
public double maxjumprange
public decimal maxjumprange
{
get => _maxjumprange;
set
Expand All @@ -504,44 +500,20 @@ public double maxjumprange
OnPropertyChanged(nameof(maxjumprange));
}
}
private double _maxjumprange;
private decimal _maxjumprange;

[JsonIgnore, Obsolete("Please use maxjumprange instead")]
public double maxjump => maxjumprange;
public decimal maxjump => maxjumprange;

[PublicAPI]
public double maxfuelperjump
{
get => _maxfuelperjump;
set
{
_maxfuelperjump = value > 0
? value
: frameshiftdrive?.GetFsdMaxFuelPerJump() ?? 0;
OnPropertyChanged(nameof(maxfuelperjump));
}
}
private double _maxfuelperjump;
[ PublicAPI, JsonIgnore]
public decimal maxfuelperjump => frameshiftdrive?.GetFsdMaxFuelPerJump() ?? 0;

[JsonIgnore, Obsolete("Please use maxfuelperjump instead")]
public double maxfuel => maxfuelperjump;

public double optimalmass
{
get => _optimalmass;
set
{
_optimalmass = value > 0
? value
: frameshiftdrive?.GetFsdOptimalMass() ?? 0;
OnPropertyChanged(nameof(optimalmass));
}
}
private double _optimalmass;
public decimal maxfuel => maxfuelperjump;

public double unladenmass { get; set; }
public decimal unladenmass { get; set; }

public double? fuelInTanks
public decimal? fuelInTanks
{
get => _fuelInTanks;
set
Expand All @@ -550,7 +522,7 @@ public double? fuelInTanks
maxjumprange = JumpRange( _fuelInTanks, 0 );
}
}
private double _fuelInTanks;
private decimal _fuelInTanks;

public int cargoCarried { get; set; }

Expand All @@ -566,7 +538,7 @@ public double? fuelInTanks
public Ship()
{ }

public Ship( string EDName, ShipManufacturer Manufacturer, string Model, string possessiveYour, List<Translation> PhoneticModel, LandingPadSize Size, int? MilitarySize, double reservoirFuelTankSize )
public Ship( string EDName, ShipManufacturer Manufacturer, string Model, string possessiveYour, List<Translation> PhoneticModel, LandingPadSize Size, int? MilitarySize, decimal reservoirFuelTankSize )
{
this.EDName = EDName;
manufacturer = Manufacturer.name;
Expand Down Expand Up @@ -706,21 +678,18 @@ public void Augment()
}
}

public JumpDetail JumpDetails(string type, double? fuelInTanksOverride = null, int? cargoCarriedOverride = null)
public JumpDetail JumpDetails(string type, decimal? fuelInTanksOverride = null, int? cargoCarriedOverride = null)
{
var currentFuel = fuelInTanksOverride ?? fuelInTanks ?? 0;
var cargoTonnage = cargoCarriedOverride ?? cargoCarried;

if (string.IsNullOrEmpty(type)) { return null; }


if (!string.IsNullOrEmpty(type))
{
switch (type)
{
case "next":
{
var jumpRange = JumpRange( Math.Min( currentFuel, maxfuelperjump ), cargoTonnage );
decimal jumpRange = JumpRange( currentFuel, cargoTonnage );
return new JumpDetail(jumpRange, 1);
}
case "max":
Expand All @@ -730,7 +699,7 @@ public JumpDetail JumpDetails(string type, double? fuelInTanksOverride = null, i
}
case "total":
{
double total = 0;
decimal total = 0;
int jumps = 0;
while (currentFuel > 0)
{
Expand All @@ -743,7 +712,7 @@ public JumpDetail JumpDetails(string type, double? fuelInTanksOverride = null, i
case "full":
{
currentFuel = fueltanktotalcapacity ?? 0;
double total = 0;
decimal total = 0;
int jumps = 0;
while ( currentFuel > 0)
{
Expand All @@ -758,21 +727,21 @@ public JumpDetail JumpDetails(string type, double? fuelInTanksOverride = null, i
return null;
}

private double JumpRange (double currentFuel, int carriedCargo, double boostModifier = 1)
private decimal JumpRange ( decimal currentFuel, int carriedCargo, double boostModifier = 1)
{
if ( frameshiftdrive is null || unladenmass == 0 || optimalmass == 0 ) { return 0; }
var mass = unladenmass + currentFuel + activeFuelReservoirCapacity + carriedCargo;
var fuel = Math.Min(currentFuel, maxfuelperjump);
if ( frameshiftdrive is null || unladenmass == 0 ) { return 0; }
var mass = Convert.ToDouble( unladenmass + currentFuel + carriedCargo);
var fuel = Convert.ToDouble( Math.Min(currentFuel, maxfuelperjump ) );

// Calculate our base max range
var baseMaxRange = (optimalmass / mass) * Math.Pow( fuel * 1000 / frameshiftdrive.GetFsdRatingConstant(), ( 1 / frameshiftdrive.GetFsdPowerConstant() ) );
var baseMaxRange = frameshiftdrive.GetFsdOptimalMass() / mass * Math.Pow( ( fuel * 1000 / frameshiftdrive.GetFsdRatingConstant() ), ( 1 / frameshiftdrive.GetFsdPowerConstant() ) );
if ( baseMaxRange == 0 ) { return 0; }

// Return the maximum range with the specified fuel and cargo levels, with a boost modifier if using synthesis or a jet cone boost
var guardianFsdBoosterRange = compartments.FirstOrDefault(c => c.module.edname.Contains("Int_GuardianFSDBooster"))?.module?.GetGuardianFSDBoost() ?? 0;
var boostFactor = Math.Pow( baseMaxRange / ( baseMaxRange + guardianFsdBoosterRange), frameshiftdrive.GetFsdPowerConstant());
var boostFactor = Math.Pow( baseMaxRange / ( baseMaxRange + guardianFsdBoosterRange ), frameshiftdrive.GetFsdPowerConstant() );

return Math.Pow( ( fuel / (boostFactor * frameshiftdrive.GetFsdRatingConstant() / 1000 ) ), (1 / frameshiftdrive.GetFsdPowerConstant() ) ) * boostFactor * optimalmass / mass;
return Convert.ToDecimal( Math.Pow( ( fuel / ( boostFactor * frameshiftdrive.GetFsdRatingConstant() / 1000 ) ), ( 1 / frameshiftdrive.GetFsdPowerConstant() ) ) * boostFactor * frameshiftdrive.GetFsdOptimalMass() / mass );
}

public static Ship FromShipyardInfo(ShipyardInfoItem item)
Expand Down
Loading

0 comments on commit d58ade5

Please sign in to comment.