diff --git a/Dat/Loaders/SoundObjectLoader.cs b/Dat/Loaders/SoundObjectLoader.cs index 9e2f7d37..d4eee145 100644 --- a/Dat/Loaders/SoundObjectLoader.cs +++ b/Dat/Loaders/SoundObjectLoader.cs @@ -60,7 +60,7 @@ public static LocoObject Load(Stream stream) private static void LoadVariable(LocoBinaryReader br, SoundObject model) { model.NumUnkStructs = br.ReadUInt32(); - var pcmDataLength = br.ReadUInt32(); // unused + _ = br.ReadUInt32(); // unused model.UnkData = br.ReadBytes((int)model.NumUnkStructs * Constants.NumUnkStructs); model.SoundObjectData = new SoundObjectData { diff --git a/Definitions/Economy.cs b/Definitions/Economy.cs new file mode 100644 index 00000000..96f28466 --- /dev/null +++ b/Definitions/Economy.cs @@ -0,0 +1,76 @@ +namespace Definitions; + +/// +/// Provides economy-related calculations for Locomotion, including inflation and cost calculations. +/// Based on OpenLoco's Economy.cpp: https://github.com/OpenLoco/OpenLoco/blob/master/src/OpenLoco/src/Economy/Economy.cpp +/// +public static class Economy +{ + // Inflation factors from OpenLoco (kInflationFactors) + private static readonly uint[] InflationFactors = + [ + 20, 20, 20, 20, 23, 20, 23, 23, + 20, 17, 17, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20, + 20, 20, 20, 20, 20, 20, 20, 20 + ]; + + /// + /// Calculates the currency multiplication factors for all 32 cost indices for a given year. + /// + /// The year to calculate inflation for (clamped to 1900-2030 range) + /// An array of 32 currency multiplication factors + public static uint[] CalculateCurrencyMultiplicationFactors(int year) + { + var factors = new uint[32]; + + // Initialize all factors to 1024 (base value) + for (var i = 0; i < 32; i++) + { + factors[i] = 1024; + } + + // OpenLoco allows 1800 as the minimum year, whereas Locomotion uses 1900. + // Treat years before 1900 as though they were 1900 to not change vanilla scenarios. + var baseYear = Math.Clamp(year, 1900, 2030) - 1900; + var monthCount = baseYear * 12; + + // Apply inflation for each month + for (var month = 0; month < monthCount; month++) + { + for (var i = 0; i < 32; i++) + { + factors[i] += (uint)((ulong)InflationFactors[i] * factors[i] >> 12); + } + } + + return factors; + } + + /// + /// Calculates the inflation-adjusted cost for a given cost factor and cost index. + /// + /// The base cost factor from the object + /// The cost index (0-31) + /// The year to calculate the cost for + /// The divisor to apply (default is 10, which is common for most objects) + /// The inflation-adjusted cost + public static int GetInflationAdjustedCost(short costFactor, byte costIndex, int year, byte divisor = 10) + { + if (costIndex >= 32) + { + throw new ArgumentOutOfRangeException(nameof(costIndex), "Cost index must be between 0 and 31"); + } + + if (divisor >= 63) + { + throw new ArgumentOutOfRangeException(nameof(divisor), "Divisor must be less than 63"); + } + + var factors = CalculateCurrencyMultiplicationFactors(year); + var val = costFactor * (long)factors[costIndex]; + var result = val / (1L << divisor); + + return (int)result; + } +} diff --git a/Definitions/ObjectModels/Graphics/ImageTableGrouper.cs b/Definitions/ObjectModels/Graphics/ImageTableGrouper.cs index 2ca41267..7def16b0 100644 --- a/Definitions/ObjectModels/Graphics/ImageTableGrouper.cs +++ b/Definitions/ObjectModels/Graphics/ImageTableGrouper.cs @@ -13,12 +13,11 @@ public static ImageTable CreateImageTable(ILocoStruct obj, ObjectType objectType ImageTableNamer.NameImages(obj, objectType, imageList); var imageTable = new ImageTable(); - try { imageTable.Groups = [.. CreateGroups(obj, objectType, imageList)]; } - catch (Exception ex) + catch (Exception) { imageTable.Groups = [new("", [.. imageList])]; } diff --git a/Gui/App.axaml b/Gui/App.axaml index c80484d2..f686c07f 100644 --- a/Gui/App.axaml +++ b/Gui/App.axaml @@ -22,6 +22,7 @@ + + diff --git a/Gui/Views/InflatableCurrencyView.cs b/Gui/Views/InflatableCurrencyView.cs new file mode 100644 index 00000000..498bcd3f --- /dev/null +++ b/Gui/Views/InflatableCurrencyView.cs @@ -0,0 +1,5 @@ +using Avalonia.Controls.Primitives; + +namespace Gui.Views; + +public class InflatableCurrencyView : TemplatedControl; diff --git a/Gui/Views/Pos3View.axaml b/Gui/Views/Pos3View.axaml index f4772b4a..df7d8ddc 100644 --- a/Gui/Views/Pos3View.axaml +++ b/Gui/Views/Pos3View.axaml @@ -8,22 +8,21 @@