Decompiled source of EconomyOverhaul v1.2.2

BepInEx/plugins/EconomyOverhaul/EconomyOverhaul.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization.Json;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using Crest;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PsychoticLab;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using cakeslice;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("EconomyOverhaul.QA")]
[assembly: InternalsVisibleTo("EconomyOverhaul.Tests")]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("EconomyOverhaul")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2")]
[assembly: AssemblyProduct("EconomyOverhaul")]
[assembly: AssemblyTitle("EconomyOverhaul")]
[assembly: AssemblyVersion("1.2.2.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace EconomyOverhaul
{
	public static class Rules
	{
		public struct PlankShape
		{
			public int look;

			public int length;

			public int width;

			public int grid;

			public int thick;

			public bool end;
		}

		public enum PalletLoad
		{
			None,
			LargeCrate,
			StandardCrate,
			SmallCrate,
			LargePackage,
			MediumPackage,
			StandardPackage,
			SmallPackage
		}

		public enum BoardSort
		{
			PerMile,
			Gold,
			Reputation
		}

		public struct SailHoles
		{
			public float Price;

			public float Hole;

			public float Area;

			public float Full;
		}

		public const double PlankRepairLeast = 0.5;

		public const double PlankRepairMost = 10.0;

		public const double PlankRepairStep = 0.5;

		public const int PlankLooks = 24;

		public const int PlankLengthCodes = 37;

		public const int PlankWidthCodes = 15;

		public const int PlankMinWidthSteps = -2;

		public const int PlankMaxWidthSteps = 12;

		public const int PlankGridSizes = 20;

		public const float PlankLength0 = 0.872f;

		public const float PlankWidth0 = 0.152f;

		public const float PlankThickness = 0.045f;

		public const float PlankMass0 = 5f;

		public const int PlankBundleCount = 8;

		public const float PlankBundleMass = 40f;

		public const float PlankMinLength = 0.5f;

		public const float PlankMaxLength = 4f;

		public const float PlankLengthStep = 0.1f;

		public const float PlankWidthStep = 0.25f;

		public const float PlankGridStep = 0.05f;

		public const int PlankMaxThickSteps = 20;

		public const int PlankGridCodes = 21;

		public const int PlankCodeSpan = 26640;

		public const int PlankTopCode = 11748239;

		public const float PoleMin = 0.2f;

		public const float PoleMax = 8f;

		public const float PoleStep = 0.1f;

		public const float PoleShopLength = 2f;

		public const float PoleKgPerMetre = 2f;

		public const float PolePush = 1.25f;

		public const float PoleFender = 1.908f;

		public const double PoleStrip = 3.4;

		public const int PoleValue = 60;

		public const int PoleBundleCount = 4;

		public const int PoleBundleValue = 240;

		public const int PoleMaxDiameterSteps = 45;

		public const float PoleDiameterStep = 0.2f;

		public const float PoleCodeSpan = 10f;

		public const float TarpFullHealth = 100f;

		public const float TarpWearPerDay = 10f;

		public const float TarpTie = 0.01f;

		public const int BundleHundredthsKicia = 10;

		public const int BundleHundredthsElsewhere = 12;

		public const int PalletHundredthsKicia = 20;

		public const int PalletHundredthsElsewhere = 24;

		public const int KiciaPort = 22;

		public const float PalletWidth = 1.45f;

		public const float PalletDepth = 1.28f;

		public const float PalletHeight = 0.25f;

		public const float PalletMass = 45f;

		public const float PalletLumber = 0.125f;

		public const int PalletValue = 750;

		public const float HalfDepth = 0.64f;

		public const float HalfMass = 22.5f;

		public const float HalfMark = -645f;

		public const int HalfValue = 375;

		public const int HalfPlanks = 5;

		public const float PalletTopBoards = 0.04f;

		public const float PalletShade = 0.85f;

		public const float RopeHalf = 0.0125f;

		public const float RopeOpening = 0.295f;

		public const float RopeBand = 0.55f;

		public const float HalfRopeOpening = 0.025f;

		public const int VendorPallets = 8;

		public const int VendorPlankBundles = 12;

		public const int VendorPoleBundles = 9;

		public const int KiciaPoleBundles = 6;

		public const float PalletStep = 0.252f;

		public const float PlankBundleStep = 0.119f;

		public const float PlankBundleAcross = 0.34f;

		public const float PoleBundleStep = 0.2f;

		public const float PlankRowsZ = 1.77f;

		public const float PoleRowsZ = 2.51f;

		public const int DemandEvents = 5;

		public const int DemandExpiryDays = 30;

		public const float DemandDoneShare = 0.2f;

		public const float LastDepartureKnown = 0.4f;

		public const float TavernFoodReach = 10f;

		public const string AskButton = "What news of other captains?";

		public const string GiveButton = "Give food";

		public const string WhereButton = "And where might I find such goods?";

		public const string AgeButton = "How old is this news?";

		private static readonly string[] LocalDemand = new string[3] { "Captains are flocking to {0}, mark me. They cannot get enough {1} there, and there's gold in it for whoever brings it.", "Word is {0} is crying out for {1}. Half the captains in this house have set their course for it already.", "There's not a crate of {1} left in {0}, they say. Any captain with a full hold will be paid handsomely." };

		private static readonly string[] ForeignDemand = new string[3] { "We don't need anything here, praise the {4}. But {0} in {2} is in sore straits: there's no {1} to be had.", "Things are well enough here. 'Tis {0} in {2} that suffers; not a barrel of {1} in the whole town, I'm told.", "A crew put in from {2}. They say {0} has gone so long without {1} its merchants pay whatever is asked." };

		private static readonly string[] LocalProducer = new string[3] { "Fortune smiles on you, captain! A patron told me {0} is drowning in {1} and selling it for a dime.", "Not far at all. {0} has more {1} than it knows what to do with; its merchants will take near any price.", "Try {0}, close by. Their warehouses are bursting with {1}, and they'll sell it cheap to be rid of it." };

		private static readonly string[] ForeignProducer = new string[3] { "A fellow just back from {2} was boasting how cheap {1} is in {0}. Worth the voyage, I'd wager.", "You'll have to sail for it. In {0}, over in {2}, there's so much {1} they all but give it away.", "Ask in {2}. A merchant who sat at that very table swore {0} sells {1} cheaper than anywhere." };

		private static readonly string[] Age = new string[3] { "The first ships set out for {0} {3}, so you'd best make haste. My thanks for the meal!", "This began {3}. Others will beat you to it if you dally. Much obliged for the food!", "It started {3}; the first sails are already over the horizon. Fair winds, and thank you kindly for the meal." };

		public const int NoCargoLimit = 999999;

		public const float LocalProfitShare = 0.02f;

		public const float WorldProfitShare = 0.05f;

		public const float DistanceFee = 0.5f;

		public const float RewardMult = 2.5f;

		public const int MissionListCap = 30;

		public const int NoMissionsFrom = 33;

		public static readonly string[] BoardSortNames = new string[3] { "Gold per mile", "Gold reward", "Reputation reward" };

		public static readonly string[] BoardRegionNames = new string[5] { "All regions", "Al'Ankh", "Emerald", "Aestrin", "Chronos" };

		public const int PristineRuinedRep = -50;

		public const int FragileTools = 33;

		public const float FragileChance = 0.5f;

		public const int FragileRuinedRep = -100;

		public const double WarehouseBand = 0.15;

		public const float TraderCapacity = 0.25f;

		public const double QuietPortPull = 0.05;

		private static readonly double[] InterestByLevel = new double[11]
		{
			0.7, 0.7, 0.6, 0.5, 0.4, 0.3, 0.25, 0.2, 0.15, 0.1,
			0.05
		};

		public const int SinkingLevels = 2;

		public const double BottomryBoxExtra = 0.1;

		public const int RentalLevel = 3;

		public const int RentalPeriod = 20;

		public const double RentalCleanShare = 0.95;

		public const int OfficeLevel = 6;

		public const float ClerkTurnRate = 60f;

		public const float ClerkMoveHintSeconds = 5f;

		public const int TreasuryPrice = 100;

		public const int ClerkPrice = 50;

		public const int CartPrice = 100;

		public const int CooperationPrice = 500;

		public const int CrewPrice = 100;

		public const int FleetPrice = 200;

		public const int ItemsPrice = 500;

		public const int WharfPrice = 1500;

		public const double ClerkSalaryValue = 166.66666666666666;

		public const int ClerkOwedDays = 30;

		internal static readonly string[] WharfFreeLines = new string[4] { "hull cleaning", "hull repair", "sail repair", "shipyard fee" };

		public static readonly float[] OasisPathLine = new float[24]
		{
			-26.628f, -93.229f, -21f, -101f, -20f, -127f, -6f, -157f, -6f, -191f,
			18f, -230f, 29f, -241f, 41f, -262f, 43f, -266f, 43f, -274f,
			47f, -284f, 66.4647f, -320.456f
		};

		public const float OasisPathHalf = 0.9f;

		public const float OasisPathSoft = 0.9f;

		public const float OasisPathGrassOver = 0.45f;

		public const float OasisPathStoneOver = 0.5f;

		public const float OasisPathJ = 32.4f;

		public const string OasisPathLayer = "Cobblestone Chaotic Red";

		public const int OasisPathGrid = 1024;

		public const float DoubledDistance = 0.05f;

		public const float DoubledDegrees = 1f;

		public const double TraderShow = 3000.0;

		public const double TraderHide = 3200.0;

		public const double TraderNear = 1000.0;

		public const string StockKey = "stock-";

		public const int OutfitAlAnkh = 0;

		public const int OutfitEmerald = 1;

		public const int OutfitAestrin = 2;

		public const int OutfitLagoon = 3;

		public const int OutfitSenna = 4;

		public const int OutfitGeneric = 5;

		public static readonly string[] OutfitNames = new string[6] { "Al'Ankh", "Emerald", "Aestrin", "Lagoon", "Senna", "generic" };

		public static readonly string[] RegionNames = new string[3] { "alankh", "emerald", "aestrin" };

		public const double StormRainBorder = 0.33;

		public const double CargoSinkEase = 10.0;

		public const double TrimMost = 80.0;

		public const double PushLeast = 0.3;

		public const double TrimHold = 7.0;

		public const double GooseOn = 170.0;

		public const double GooseOff = 165.0;

		public const double BraceMost = 70.0;

		public const double SquareSetAt = 36.0;

		public const double SquareFurlUnder = 33.0;

		public const double AllSquareBraceMost = 80.0;

		public const string FleetSailRefusal = "Fisherman's sails can't\njoin the trade fleet.";

		public const double SidePastBy = 5.0;

		public const double TraderWindLow = 7.0;

		public const double TraderWindHigh = 21.0;

		public const double TraderStrengthLow = 0.75;

		public const double TraderStrengthHigh = 1.25;

		private static readonly double[] TraderCourseFactor = new double[5] { 1.1, 1.2, 1.0, 0.86, 0.8 };

		public const double CabinWall = 6.62;

		public const double CabinBack = 2.1;

		public const double CabinFloor = 0.87;

		public const double CabinDoorEnd = 8.4;

		private static readonly double[] stairZ = new double[6] { 6.62, 6.8, 7.2, 7.6, 8.0, 8.4 };

		private static readonly double[] stairY = new double[6] { 0.85, 1.04, 1.28, 1.47, 1.69, 1.93 };

		public const double FrontDeckY = 1.93;

		public const double FrontDeckBack = 8.8;

		private const double FrontDeckRow0 = 8.96;

		private const double FrontDeckCell = 0.2;

		private static readonly double[] frontDeckHalf = new double[14]
		{
			1.8, 1.6, 1.8, 1.6, 1.6, 1.6, 1.4, 1.4, 1.4, 1.2,
			1.2, 1.0, 1.0, 0.8
		};

		public const double CopySolidSpeed = 15.0;

		public const double FurlRate = 0.15;

		public const double LegSpread = 20.0;

		public const double LegRoomSpare = 3.0;

		public const double SternwayShare = 0.5;

		public const double SternFirstOver = 90.0;

		public const double KeepHeadingOver = 10.0;

		public const double TurnFullUnder = 10.0;

		public const double TurnStopOver = 60.0;

		public const double LaneEaseStretch = 300.0;

		public const double StraightMin = 5.0;

		public const double StraightMax = 50.5;

		public const double StraightAxis = 2.0;

		public const double StraightFullUnder = 2.0;

		public const double StraightStopOver = 6.0;

		public const double StopShort = 8.0;

		public const double StopEase = 20.0;

		public const double WayMargin = 2.0;

		public const double SingleFileSpare = 6.0;

		public const double KeepRightUnder = 40.0;

		public const double KeepRightEdge = 2.0;

		public const double KeepRightAhead = 20.0;

		public const double BesideGap = 3.0;

		public const double AnchorGap = 4.0;

		public const double AnchorTolerance = 0.1;

		public const double LanternMastNear = 1.0;

		public const double LanternMastOff = 0.4;

		private static readonly Dictionary<int, int> mainCount = new Dictionary<int, int>();

		public const double RepLookSeconds = 8.0;

		public const double RepLookLeast = 60.0;

		public const double RepLookMost = 300.0;

		public const double RepCorridorMid = 3.0;

		public const double RepCorridorHigh = 10.0;

		public const double StillUnder = 0.3;

		public const double RepAsideSpare = 3.0;

		public const double RepClearHigh = 10.0;

		public const double SingleFileSpareHigh = 10.0;

		public const double BesideGapSea = 15.0;

		public const double GiveSlowFrom = 60.0;

		public const double GiveStop = 20.0;

		public const double GiveBackUnder = 12.0;

		public const double GiveBackFastUnder = 8.0;

		public const double GiveBackShare = 0.25;

		public const double GiveBackMost = 1.0;

		public const double GiveBackFast = 0.75;

		public const double GiveClear = 3.0;

		public const double StillWait = 60.0;

		public const double GreetWithin = 40.0;

		public const double GreetAgain = 300.0;

		public const double GreetShow = 15.0;

		public const double BerthLineShow = 30.0;

		public const int GreetMost = 2;

		public const double HarbourSpare = 50.0;

		public const double ComingIn = 0.5;

		public const double YieldWithin = 60.0;

		public const double KeptStill = 600.0;

		private static readonly float[] CrackCuts = new float[11]
		{
			0.8471f, 0.5725f, 0.4824f, 0.3804f, 0.2941f, 0.2275f, 0.1647f, 0.1098f, 0.0745f, 0.0471f,
			0.0353f
		};

		public const double ImmersionPerHour = 12.5;

		public const double RainAtImmersionRate = 8.0;

		public const float RainThreshold = 0.1f;

		public const float RuinedCondition = 19.5f;

		public const float DryingCeiling = 80f;

		public const float LuxuryDryingCeiling = 50f;

		public const double ClearDayDryingPerHour = 1.4457831325301205;

		public const double ImmersionStart = 0.14;

		public const double HalfLight = 0.2;

		public const int LanternCoverLeast = 20;

		public const int LanternCoverMost = 90;

		public const int LanternCoverDefault = 70;

		public const int BigLanternCoverLess = 20;

		public const int BigLanternPrefab = 133;

		public static readonly double[] WaterDamageSpeeds = new double[4] { 0.25, 0.5, 0.75, 1.0 };

		public static readonly double[] DryingSpeeds = new double[6] { 0.0, 1.0, 1.5, 2.0, 2.5, 3.0 };

		public const float WaterHoldSeconds = 10f;

		public const int OpenedBarrelPrice = 25;

		public static readonly Color WetOutlineColor = new Color(0.05f, 0.15f, 0.75f);

		public static readonly Color DryingOutlineColor = new Color(1f, 0.75f, 0.1f);

		public static float PoleBundleMass => PoleMass(2.0) * 4f;

		public static int PlanksPerPercent(int boatPrice, double capacity, double lumberValue)
		{
			double num = ((boatPrice > 0 && lumberValue > 0.0) ? ((double)boatPrice * 3.5 * 0.01 * capacity * 0.1 / (lumberValue / 128.0)) : (capacity / 120.0));
			if (!double.IsNaN(num) && !(num < 1.5))
			{
				return (int)Math.Min(1000000.0, Math.Round(num, MidpointRounding.AwayFromZero));
			}
			return 1;
		}

		public static double PlankRepairPercent(double percent)
		{
			if (!double.IsNaN(percent))
			{
				return Math.Max(0.5, Math.Min(10.0, Math.Round(percent / 0.5, MidpointRounding.AwayFromZero) * 0.5));
			}
			return 0.5;
		}

		public static string PercentText(double percent)
		{
			return percent.ToString("0.#", CultureInfo.InvariantCulture);
		}

		public static string HullHintFixed(double progress, double damage, double percent)
		{
			string[] array = HullHint(progress, damage, 1).Split(new char[1] { '\n' });
			return array[0] + "\n" + array[1] + "\nHull repaired per plank: " + PercentText(PlankRepairPercent(percent)) + "%";
		}

		public static bool Caulked(double oakum, double damage, double capacity)
		{
			if (capacity > 0.0 && damage > 0.0)
			{
				return oakum + 0.01 >= Math.Min(0.01, damage) * capacity;
			}
			return false;
		}

		public static string HullHint(double progress, double damage, int planks)
		{
			int num = ((progress >= 1.0) ? 100 : ((progress > 0.0) ? Math.Min(99, (int)Math.Floor(progress * 100.0 + 0.0001)) : 0));
			return num + "%\nShip hull damage: " + (damage * 100.0).ToString("0.00", CultureInfo.InvariantCulture) + "%\nPlanks required to fix 1%: " + planks;
		}

		public static int PlankLook(bool lumber, int i, int k, int j)
		{
			if (!lumber)
			{
				return 4 * i + 2 * k + j;
			}
			return 8 + 4 * i + j;
		}

		public static bool PlankTable(bool sold, bool nailed, bool placement, bool wallItemHeld)
		{
			if (sold && nailed && placement)
			{
				return !wallItemHeld;
			}
			return false;
		}

		public static float PlankCode(PlankShape s)
		{
			int num = Clamp(s.grid, 0, 20);
			int num2 = ((num <= 0) ? ((Clamp(s.width, -2, 12) + 15) % 15) : 0);
			return (float)(Clamp(s.look, 0, 23) + 24 * (Clamp(s.length, 0, 36) + 37 * (num2 + 15 * (s.end ? 1 : 0)))) + 26640f * (float)(Clamp(s.thick, 0, 20) + 21 * num);
		}

		public static PlankShape PlankDecode(double health)
		{
			if (double.IsNaN(health) || double.IsInfinity(health) || health < 0.0 || health > 11748239.0)
			{
				return default(PlankShape);
			}
			int num = (int)Math.Round(health);
			int look = num % 24;
			num /= 24;
			int length = num % 37;
			num /= 37;
			int num2 = num % 15;
			num /= 15;
			int num3 = num / 2;
			int num4 = num3 / 21;
			return new PlankShape
			{
				look = look,
				length = length,
				width = ((num4 <= 0) ? ((num2 <= 12) ? num2 : (num2 - 15)) : 0),
				grid = num4,
				end = (num % 2 == 1),
				thick = num3 % 21
			};
		}

		private static int Clamp(int x, int lo, int hi)
		{
			if (x >= lo)
			{
				if (x <= hi)
				{
					return x;
				}
				return hi;
			}
			return lo;
		}

		public static float PlankLength(int code)
		{
			if (code > 0 && code < 37)
			{
				return (float)Math.Round(0.5f + (float)(code - 1) * 0.1f, 1);
			}
			return 0.872f;
		}

		public static int PlankLengthStepped(int code, int step)
		{
			if (step == 0)
			{
				return code;
			}
			if (code <= 0 || code >= 37)
			{
				return (int)Math.Round((((step > 0) ? (Math.Ceiling(8.720000313354491) / 10.0) : (Math.Floor(8.719998313354493) / 10.0)) - 0.5) / 0.10000000149011612) + 1;
			}
			return Clamp(code + step, 1, 36);
		}

		public static float PlankWidth(int steps)
		{
			return 0.152f * (1f + 0.25f * (float)Clamp(steps, -2, 12));
		}

		public static float PlankGrid(int size)
		{
			return 0.05f * (float)Clamp(size, 1, 20);
		}

		public static float PlankWidth(PlankShape s)
		{
			if (s.grid <= 0)
			{
				return PlankWidth(s.width);
			}
			return PlankGrid(s.grid);
		}

		public static float PlankThick(int thick)
		{
			if (thick > 0)
			{
				return PlankGrid(thick);
			}
			return 0.045f;
		}

		public static float PlankThickScale(int thick)
		{
			return PlankThick(thick) / 0.045f;
		}

		public static PlankShape PlankWider(PlankShape s, int step)
		{
			if (step == 0)
			{
				return s;
			}
			double num = (double)PlankWidth(s) / 0.05000000074505806;
			int x = ((step > 0) ? ((int)Math.Floor(num + 0.0001) + 1) : ((int)Math.Ceiling(num - 0.0001) - 1));
			s.grid = Clamp(x, 1, 20);
			s.width = 0;
			return s;
		}

		public static float PlankMass(PlankShape s)
		{
			return 5f * PlankLength(s.length) * PlankWidth(s) / 0.132544f * PlankThickScale(s.thick);
		}

		public static bool PlankPlain(PlankShape s)
		{
			if (s.length == 0 && s.width == 0 && s.grid == 0 && s.thick == 0)
			{
				return !s.end;
			}
			return false;
		}

		public static string WeightText(float lb)
		{
			return ", " + ((lb < 99.95f) ? lb.ToString("F1", CultureInfo.InvariantCulture) : Math.Round(lb).ToString("F0", CultureInfo.InvariantCulture)) + " lb";
		}

		public static float RestLift(float side, float up, float halfSide, float halfUp, bool round)
		{
			if (!round)
			{
				return halfSide * Math.Abs(side) + halfUp * Math.Abs(up);
			}
			return halfSide * (float)Math.Sqrt(side * side + up * up);
		}

		public static double PoleGrain(double d)
		{
			return Mirrored(d, 3.4);
		}

		public static double Mirrored(double d, double strip)
		{
			double num = 2.0 * strip;
			double num2 = (d % num + num) % num;
			if (!(num2 <= strip))
			{
				return num - num2;
			}
			return num2;
		}

		public static double Eased(double t)
		{
			t = Clamp(t, 0.0, 1.0);
			return t * t * (3.0 - 2.0 * t);
		}

		public static int PoleTenths(double metres)
		{
			if (!double.IsNaN(metres) && !double.IsInfinity(metres))
			{
				return (int)Math.Round(Clamp(metres, 0.20000000298023224, 8.0) * 10.0);
			}
			return (int)Math.Round(20.0);
		}

		public static float PoleLength(double metres)
		{
			return (float)PoleTenths(metres) / 10f;
		}

		public static float PoleMass(double metres)
		{
			return PoleLength(metres) * 2f;
		}

		public static int PoleDiameterSteps(double health)
		{
			if (!double.IsNaN(health) && !double.IsInfinity(health) && !(health < 10.0))
			{
				return Clamp((int)Math.Floor(health / 10.0), 0, 45);
			}
			return 0;
		}

		public static float PoleLengthOf(double health)
		{
			return PoleLength(health - (double)(10f * (float)PoleDiameterSteps(health)));
		}

		public static float PoleCode(double metres, int steps)
		{
			return PoleLength(metres) + 10f * (float)Clamp(steps, 0, 45);
		}

		public static float PoleDiameterScale(int steps)
		{
			return 1f + 0.2f * (float)Clamp(steps, 0, 45);
		}

		public static float PoleMass(double metres, int steps)
		{
			float num = PoleDiameterScale(steps);
			return PoleMass(metres) * num * num;
		}

		public static float RepairedHealth(float tarp, float pack)
		{
			return Math.Min(100f, Math.Max(0f, Finite(tarp)) + Math.Max(0f, Finite(pack)));
		}

		public static float TarpHealth(float startHealth, double startClock, double now, bool wearing)
		{
			return (float)Clamp(wearing ? ((double)Finite(startHealth) - 10.0 * Math.Max(0.0, now - startClock)) : ((double)Finite(startHealth)), 0.0, 100.0);
		}

		private static float Finite(float x)
		{
			if (!float.IsNaN(x) && !float.IsInfinity(x))
			{
				return x;
			}
			return 0f;
		}

		public static int TearSeed(float[] sides)
		{
			int num = 17;
			foreach (int item in from x in sides
				select (int)Math.Round(x * 10f) into x
				orderby x
				select x)
			{
				num = num * 31 + item;
			}
			return num;
		}

		public static int TarpClaim(IList<(float h, bool end, float dist)> c)
		{
			if (c == null || c.Count == 0)
			{
				return -1;
			}
			float num = c.Max(((float h, bool end, float dist) x) => x.h);
			int num2 = -1;
			for (int num3 = 0; num3 < c.Count; num3++)
			{
				if (!(c[num3].h < num - 0.01f) && (num2 < 0 || (c[num3].end && !c[num2].end) || (c[num3].end == c[num2].end && c[num3].dist < c[num2].dist)))
				{
					num2 = num3;
				}
			}
			return num2;
		}

		public static int WoodHundredths(bool pallet, int port)
		{
			if (!pallet)
			{
				if (port != 22)
				{
					return 12;
				}
				return 10;
			}
			if (port != 22)
			{
				return 24;
			}
			return 20;
		}

		public static int WoodShare(int lumber, int hundredths)
		{
			return (int)Math.Ceiling((double)((long)lumber * (long)hundredths) / 100.0);
		}

		public static bool IsHalfMark(float health)
		{
			return health == -645f;
		}

		public static List<(string key, string what)> RodHintLines(bool pole, bool endMode, bool sizeFixed, string brace, string length = "Q/E", string width = "O/L", string thick = "I/K")
		{
			List<(string, string)> list = new List<(string, string)>();
			if (pole || endMode)
			{
				if (!sizeFixed)
				{
					list.AddRange(RodSizeLines(pole, length, width, thick));
				}
				list.Add((brace, pole ? "brace" : "repair mode"));
			}
			else
			{
				list.Add((brace, "placement mode"));
			}
			return list;
		}

		public static List<(string key, string what)> RodSizeLines(bool pole, string length = "Q/E", string width = "O/L", string thick = "I/K")
		{
			List<(string, string)> list = new List<(string, string)>
			{
				(length, "length"),
				(width, pole ? "diameter" : "width")
			};
			if (!pole)
			{
				list.Add((thick, "thickness"));
			}
			return list;
		}

		public static List<string> PointedControlLines(string game, List<(string key, string what)> sizes, out int sizeLines)
		{
			string[] array = (game ?? "").Split(new char[1] { '\n' });
			List<string> list = sizes.Select(((string key, string what) s) => s.what).ToList();
			sizeLines = list.Count;
			for (int num = ((array.Length >= 2 && array[0].Length == 0) ? 1 : 0); num < array.Length; num++)
			{
				list.Add(array[num]);
			}
			return list;
		}

		public static bool Roped(int slots, int loaded, int nailed)
		{
			if (slots > 0 && loaded == slots)
			{
				return nailed == slots;
			}
			return false;
		}

		public static (Vector3 min, Vector3 max) LoadBox(PalletLoad load, bool half = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = LoadSize(load, half);
			Vector3 val2 = Vector3.positiveInfinity;
			Vector3 val3 = Vector3.negativeInfinity;
			Vector3[] array = LoadSlots(load, half);
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val4 = array[i] + new Vector3(0f, 0.25f + val.y / 2f, 0f);
				val2 = Vector3.Min(val2, val4 - val / 2f);
				val3 = Vector3.Max(val3, val4 + val / 2f);
			}
			return (min: val2, max: val3);
		}

		public static List<Vector3[]> RopeLoops(PalletLoad load, bool half = false)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3[]> list = new List<Vector3[]>();
			if (LoadSlots(load, half).Length == 0)
			{
				return list;
			}
			(Vector3 min, Vector3 max) tuple = LoadBox(load, half);
			Vector3 item = tuple.min;
			Vector3 item2 = tuple.max;
			float num = 0.0125f;
			float num2 = Math.Max(Math.Max(0f - item.x, item2.x), 0.725f) + num;
			float num3 = item2.y + num;
			float num4 = 0.21000001f - num;
			float[] array = ((!half) ? new float[2] { -0.295f, 0.295f } : new float[1] { 0.025f });
			foreach (float num5 in array)
			{
				list.Add((Vector3[])(object)new Vector3[4]
				{
					new Vector3(0f - num2, num4, num5),
					new Vector3(0f - num2, num3, num5),
					new Vector3(num2, num3, num5),
					new Vector3(num2, num4, num5)
				});
			}
			float num6 = 0.25f + (item2.y - 0.25f) * 0.55f;
			float num7 = Math.Max(0f - item.x, item2.x) + num;
			float num8 = Math.Max(0f - item.z, item2.z) + num;
			list.Add((Vector3[])(object)new Vector3[4]
			{
				new Vector3(0f - num7, num6, 0f - num8),
				new Vector3(0f - num7, num6, num8),
				new Vector3(num7, num6, num8),
				new Vector3(num7, num6, 0f - num8)
			});
			return list;
		}

		public static PalletLoad LoadOf(string sizeDescription)
		{
			return (sizeDescription ?? "").Trim().ToLowerInvariant() switch
			{
				"large crate" => PalletLoad.LargeCrate, 
				"standard crate" => PalletLoad.StandardCrate, 
				"small crate" => PalletLoad.SmallCrate, 
				"large package" => PalletLoad.LargePackage, 
				"medium package" => PalletLoad.MediumPackage, 
				"standard package" => PalletLoad.StandardPackage, 
				"small package" => PalletLoad.SmallPackage, 
				_ => PalletLoad.None, 
			};
		}

		public static Vector3 LoadSize(PalletLoad load, bool half = false)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			if (half && load == PalletLoad.StandardCrate)
			{
				return new Vector3(1.27f, 1.029f, 0.71f);
			}
			if (half && load == PalletLoad.MediumPackage)
			{
				return new Vector3(1.216f, 1.016f, 0.698f);
			}
			return (Vector3)(load switch
			{
				PalletLoad.LargeCrate => new Vector3(1.27f, 1.093f, 1.229f), 
				PalletLoad.StandardCrate => new Vector3(0.71f, 1.029f, 1.27f), 
				PalletLoad.SmallCrate => new Vector3(0.462f, 1.056f, 0.626f), 
				PalletLoad.LargePackage => new Vector3(1.436f, 0.968f, 1.46f), 
				PalletLoad.MediumPackage => new Vector3(0.698f, 1.016f, 1.216f), 
				PalletLoad.StandardPackage => new Vector3(1.866f, 1.066f, 0.606f), 
				PalletLoad.SmallPackage => new Vector3(1.466f, 1.066f, 0.406f), 
				_ => Vector3.zero, 
			});
		}

		public static Vector3[] LoadSlots(PalletLoad load, bool half)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (!half)
			{
				return LoadSlots(load);
			}
			switch (load)
			{
			case PalletLoad.StandardCrate:
			case PalletLoad.MediumPackage:
			case PalletLoad.StandardPackage:
			case PalletLoad.SmallPackage:
				return (Vector3[])(object)new Vector3[1] { Vector3.zero };
			case PalletLoad.SmallCrate:
				return (Vector3[])(object)new Vector3[3]
				{
					new Vector3(-0.478f, 0f, 0f),
					Vector3.zero,
					new Vector3(0.478f, 0f, 0f)
				};
			default:
				return (Vector3[])(object)new Vector3[0];
			}
		}

		public static Vector3[] LoadSlots(PalletLoad load)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			switch (load)
			{
			case PalletLoad.LargeCrate:
			case PalletLoad.LargePackage:
				return (Vector3[])(object)new Vector3[1] { Vector3.zero };
			case PalletLoad.StandardCrate:
				return (Vector3[])(object)new Vector3[2]
				{
					new Vector3(-0.36f, 0f, 0f),
					new Vector3(0.36f, 0f, 0f)
				};
			case PalletLoad.SmallCrate:
				return new float[3] { -0.478f, 0f, 0.478f }.SelectMany((float x) => (IEnumerable<Vector3>)(object)new Vector3[2]
				{
					new Vector3(x, 0f, -0.32f),
					new Vector3(x, 0f, 0.32f)
				}).ToArray();
			case PalletLoad.MediumPackage:
				return (Vector3[])(object)new Vector3[2]
				{
					new Vector3(-0.352f, 0f, 0f),
					new Vector3(0.352f, 0f, 0f)
				};
			case PalletLoad.StandardPackage:
				return (Vector3[])(object)new Vector3[2]
				{
					new Vector3(0f, 0f, -0.31f),
					new Vector3(0f, 0f, 0.31f)
				};
			case PalletLoad.SmallPackage:
				return (Vector3[])(object)new Vector3[3]
				{
					new Vector3(0f, 0f, -0.42f),
					Vector3.zero,
					new Vector3(0f, 0f, 0.42f)
				};
			default:
				return (Vector3[])(object)new Vector3[0];
			}
		}

		public static (int z, int y) LoadAxes(Vector3 size, Vector3 want)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			int[] array = null;
			float num = float.MaxValue;
			int[][] array2 = new int[6][]
			{
				new int[3] { 0, 1, 2 },
				new int[3] { 0, 2, 1 },
				new int[3] { 1, 0, 2 },
				new int[3] { 1, 2, 0 },
				new int[3] { 2, 0, 1 },
				new int[3] { 2, 1, 0 }
			};
			foreach (int[] array3 in array2)
			{
				float num2 = Math.Abs(((Vector3)(ref size))[array3[0]] - want.x) + Math.Abs(((Vector3)(ref size))[array3[1]] - want.y) + Math.Abs(((Vector3)(ref size))[array3[2]] - want.z);
				if (num2 < num)
				{
					num = num2;
					array = array3;
				}
			}
			return (z: Array.IndexOf(array, 2), y: Array.IndexOf(array, 1));
		}

		public static int PoleBundlesAt(bool shared)
		{
			if (!shared)
			{
				return 9;
			}
			return 6;
		}

		public static int PoleColumnsAt(bool shared)
		{
			return 3;
		}

		public static bool DemandPort(int port)
		{
			if (port != 33 && port != 21 && port != 7)
			{
				return port != 8;
			}
			return false;
		}

		public static bool DemandGood(int good)
		{
			if (good > 1 && good < 64 && good != 45 && good != 51 && good != 31 && good != 32 && good != 46)
			{
				return good != 52;
			}
			return false;
		}

		public static bool DemandFits(float production, float supply, float cap)
		{
			if (production <= 0f && supply < 1f)
			{
				return supply > DemandTarget(cap);
			}
			return false;
		}

		public static bool DemandProducer(float production)
		{
			return production > 0f;
		}

		public static float DemandTarget(float cap)
		{
			return 0f - cap;
		}

		public static float ProducerTarget(float cap, float supply)
		{
			return Math.Max(supply, cap);
		}

		public static float DemandDone(float cap)
		{
			return -0.2f * cap;
		}

		public static bool DemandComplete(float supply, float cap)
		{
			return supply > DemandDone(cap);
		}

		public static bool DemandExpired(int startDay, int day)
		{
			return day - startDay >= 30;
		}

		public static int DemandNeed(float supply, int inFlight, float cap)
		{
			if (!DemandComplete(supply, cap))
			{
				return Math.Max(0, (int)Math.Floor(DemandDone(cap) - supply) + 1 - inFlight);
			}
			return 0;
		}

		public static bool KnowsLastDeparture(float roll)
		{
			return roll < 0.4f;
		}

		public static bool DemandFetch(int need, int unitsHeadingThere)
		{
			return need > unitsHeadingThere;
		}

		public static bool DemandReported(int reportDay, float reportSupply, int startDay, float reportCap)
		{
			if (reportDay >= startDay)
			{
				return !DemandComplete(reportSupply, reportCap);
			}
			return false;
		}

		public static bool ProducerReported(int reportDay, float reportSupply, int startDay, float reportCap, int tier)
		{
			if (reportDay >= startDay)
			{
				return reportSupply >= (float)(1 - PurchaseDeficit(reportCap, tier));
			}
			return false;
		}

		public static string FoodLine(string food)
		{
			return "Talk of other captains, is it? That's hungry work. Fetch us a plate of " + food + " and I'll tell you what I hear.";
		}

		public static string When(int days)
		{
			if (days > 0)
			{
				if (days != 1)
				{
					return days + " days ago";
				}
				return "but a day ago";
			}
			return "this very day";
		}

		public static string Ruler(int region)
		{
			return region switch
			{
				1 => "Trade Prince", 
				0 => "Sultan", 
				_ => "King", 
			};
		}

		public static string NewsLine(int kind, bool local, int variant, string port, string good, string region, int days, string ruler = "Sultan")
		{
			string[] array = kind switch
			{
				1 => local ? LocalProducer : ForeignProducer, 
				0 => local ? LocalDemand : ForeignDemand, 
				_ => Age, 
			};
			return string.Format(array[(variant % array.Length + array.Length) % array.Length], port, good, region, When(days), ruler);
		}

		public static int PickNews(IList<(int id, bool local, double distance)> events, ICollection<int> heard)
		{
			int num = Pick(events.Where(((int id, bool local, double distance) e) => !heard.Contains(e.id)));
			if (num < 0)
			{
				return Pick(events);
			}
			return num;
			static int Pick(IEnumerable<(int id, bool local, double distance)> from)
			{
				List<(int, bool, double)> list = from.ToList();
				if (list.Count == 0)
				{
					return -1;
				}
				List<(int, bool, double)> list2 = list.Where<(int, bool, double)>(((int id, bool local, double distance) e) => e.local).ToList();
				if (list2.Count <= 0)
				{
					return (from e in list
						orderby e.distance, e.id descending
						select e).First().Item1;
				}
				return list2.Max<(int, bool, double)>(((int id, bool local, double distance) e) => e.id);
			}
		}

		public static string Wrap(string text, int width = 33)
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = 0;
			string[] array = text.Split(new char[1] { ' ' });
			foreach (string text2 in array)
			{
				if (num > 0 && num + text2.Length + 1 > width)
				{
					stringBuilder.Append('\n');
					num = 0;
				}
				else if (num > 0)
				{
					stringBuilder.Append(' ');
					num++;
				}
				stringBuilder.Append(text2);
				num += text2.Length;
			}
			return stringBuilder.ToString();
		}

		public static bool EnsureOwnReport(PriceReport[] known, int self)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if (known == null || self < 0 || self >= known.Length || known[self] != null)
			{
				return false;
			}
			known[self] = new PriceReport();
			return true;
		}

		public static int PurchaseDeficit(double cap, int tier)
		{
			double num;
			switch (tier)
			{
			default:
				return 0;
			case 3:
			case 4:
				num = 0.02;
				break;
			case 2:
				num = 0.05;
				break;
			case 1:
				num = 0.1;
				break;
			}
			double num2 = num;
			return checked((int)Math.Round(cap * num2, MidpointRounding.AwayFromZero));
		}

		public static bool PurchaseOriginAllowed(int port, int good)
		{
			if (good == 64)
			{
				return port == 33;
			}
			return true;
		}

		public static double FlowFactor(double supply, double production, double cap, bool saffron, double productionDeficitLimit)
		{
			double num = Clamp(1.0 - Math.Abs(supply) / cap, 0.0, 1.0);
			if (saffron)
			{
				return num * num;
			}
			if (production > 0.0)
			{
				if (!(supply >= 0.0))
				{
					return 1.0 + ((productionDeficitLimit > 0.0) ? Clamp((0.0 - supply) / productionDeficitLimit, 0.0, 1.0) : 1.0);
				}
				return num * num;
			}
			if (!(supply >= 0.0))
			{
				return num * num;
			}
			return 1.0;
		}

		public static double Price(double value, double supply, double cap, double surplus, double deficit, int good = 0)
		{
			double num = PriceCurves.Response(supply, cap, good);
			if (PriceCurves.TryProfile(good, out var _))
			{
				surplus = PriceCurves.SurplusMultiplier((float)surplus, good);
				deficit = PriceCurves.DeficitMultiplier((float)deficit, good);
				float num2 = (float)Math.Sqrt(1.0 - num);
				float num3 = 1f - num2 * num2;
				float num4 = ((supply >= 0.0) ? num3 : (0f - num3));
				float num5 = (float)value;
				return Round(num5 - num5 * (float)((supply >= 0.0) ? surplus : deficit) * num4);
			}
			return Math.Round(value * ((supply >= 0.0) ? (1.0 - surplus * num) : (1.0 + deficit * num)), MidpointRounding.ToEven);
		}

		public static double Spread(double price)
		{
			return 0.005 + -0.0049 * Clamp((price - 1000.0) / 29000.0, 0.0, 1.0);
		}

		public static int Quote(double value, double supply, double cap, double surplus, double deficit, bool buy, int good = 0)
		{
			double num = Price(value, supply, cap, surplus, deficit, good);
			return Round(num * (1.0 + (double)(buy ? 1 : (-1)) * Spread(num)));
		}

		public static int[] MigrationSales(int[] warehouse, int stockLength)
		{
			return (warehouse ?? new int[0]).Where((int g) => g > 0 && g < stockLength).ToArray();
		}

		public static MissionCategory Category(int good)
		{
			if (!PriceCurves.TryProfile(good, out var profile))
			{
				return MissionCategory.None;
			}
			return profile switch
			{
				PriceProfile.Staple => MissionCategory.Staple, 
				PriceProfile.ConsumerGoods => MissionCategory.ConsumerGoods, 
				PriceProfile.Industrial => MissionCategory.Industrial, 
				_ => MissionCategory.Luxury, 
			};
		}

		public static string CategoryName(MissionCategory c)
		{
			return c switch
			{
				MissionCategory.Luxury => "Luxury", 
				MissionCategory.Industrial => "Industrial", 
				MissionCategory.ConsumerGoods => "Consumer goods", 
				MissionCategory.Staple => "Staple", 
				_ => "", 
			};
		}

		public static int CategoryRep(MissionCategory c)
		{
			return c switch
			{
				MissionCategory.Luxury => 2, 
				MissionCategory.Industrial => 1, 
				_ => 0, 
			};
		}

		public static int GoodRep(int good)
		{
			switch (good)
			{
			case 34:
			case 41:
			case 55:
			case 56:
				return 3;
			case 20:
				return 4;
			case 22:
				return 5;
			default:
				return CategoryRep(Category(good));
			}
		}

		public static float CategoryGold(MissionCategory c)
		{
			if (c != MissionCategory.Staple)
			{
				if (c != MissionCategory.ConsumerGoods)
				{
					if (c != MissionCategory.Industrial)
					{
						return (c != MissionCategory.Luxury) ? 1 : 2;
					}
					return 1.5f;
				}
				return 1.25f;
			}
			return 1.1f;
		}

		public static float CategoryReputation(MissionCategory c)
		{
			return c switch
			{
				MissionCategory.Luxury => 0.7f, 
				MissionCategory.Industrial => 0.9f, 
				MissionCategory.ConsumerGoods => 1.1f, 
				MissionCategory.Staple => 1.3f, 
				_ => 1f, 
			};
		}

		public static float CategoryDistance(MissionCategory c)
		{
			return c switch
			{
				MissionCategory.ConsumerGoods => 1.1f, 
				MissionCategory.Staple => 1.5f, 
				_ => 1f, 
			};
		}

		public static float CategoryCargo(MissionCategory c)
		{
			return (c != MissionCategory.Staple && c != MissionCategory.ConsumerGoods) ? 1 : 2;
		}

		public static int CategoryCargoOffset(MissionCategory c)
		{
			return c switch
			{
				MissionCategory.Luxury => -1, 
				MissionCategory.ConsumerGoods => -3, 
				MissionCategory.Staple => -2, 
				_ => 0, 
			};
		}

		public static int CapacityAward(MissionCategory c, bool world, bool origin)
		{
			int num;
			switch (c)
			{
			case MissionCategory.Staple:
				num = 3;
				break;
			case MissionCategory.ConsumerGoods:
				num = 2;
				break;
			case MissionCategory.Industrial:
				num = (origin ? 1 : 3);
				break;
			case MissionCategory.Luxury:
				num = ((!origin) ? 1 : 3);
				break;
			default:
				if (!origin)
				{
					if (!world)
					{
						return 1;
					}
					return 3;
				}
				if (!world)
				{
					return 2;
				}
				return 6;
			}
			if (!world)
			{
				return num;
			}
			return 2 * num;
		}

		public static int CargoTable(int level)
		{
			if (level >= 6)
			{
				return level switch
				{
					8 => 11, 
					7 => 10, 
					6 => 9, 
					_ => 999999, 
				};
			}
			return Math.Max(0, level) + 3;
		}

		public static int MissionCargo(int level, MissionCategory c)
		{
			int num = CargoTable(level);
			if (num != 999999)
			{
				return Math.Max(1, (int)Math.Floor((double)num * (double)CategoryCargo(c) + 0.5) + CategoryCargoOffset(c));
			}
			return 999999;
		}

		public static float MissionGold(float profit, float distance, bool ocean, MissionCategory c)
		{
			return (profit * (ocean ? 0.05f : 0.02f) + distance * 0.5f * CategoryDistance(c)) * 2.5f * CategoryGold(c);
		}

		public static bool MissionWorthwhile(float profit, float distance)
		{
			return distance * 0.5f <= profit;
		}

		public static int MissionTotal(float unitProfit, int count, float distance, bool ocean, MissionCategory c)
		{
			if (count > 0)
			{
				return Mathf.RoundToInt(MissionGold(unitProfit * (float)count, distance, ocean, c)) / count * count;
			}
			return 0;
		}

		public static int MaxMissions(int level)
		{
			return Math.Min(5, Math.Max(0, level) + 2);
		}

		public static bool[] KeepOffers(bool[] mail, int cap)
		{
			int cargo = 0;
			return mail.Select((bool m) => m || cargo++ < cap).ToArray();
		}

		public static bool[] KeepOffersByPay(float[] pay, bool[] mail, int cap)
		{
			int[] array = (from i in Enumerable.Range(0, pay.Length)
				orderby pay[i] descending
				select i).ToArray();
			bool[] array2 = KeepOffers(array.Select((int i) => mail[i]).ToArray(), cap);
			bool[] array3 = new bool[pay.Length];
			for (int num = 0; num < array.Length; num++)
			{
				array3[array[num]] = array2[num];
			}
			return array3;
		}

		public static bool[] KeepAfterAccept(int[] counts, int stock)
		{
			return counts.Select((int c) => c > 0 && c <= stock).ToArray();
		}

		public static double RealValue(int amount, float rate)
		{
			if (!(rate > 0f))
			{
				return amount;
			}
			return (double)amount / (double)rate;
		}

		public static double BoardKey(BoardSort sort, double realTotal, float distance, int reputation)
		{
			switch (sort)
			{
			default:
				if (!(distance > 0f))
				{
					return realTotal;
				}
				return realTotal / (double)distance;
			case BoardSort.Reputation:
				return reputation;
			case BoardSort.Gold:
				return realTotal;
			}
		}

		public static int[] BoardOrder(double[] keys, int[] regions, int region)
		{
			return (from i in Enumerable.Range(0, keys.Length)
				where region < 0 || regions[i] == region
				orderby keys[i] descending
				select i).ToArray();
		}

		public static bool QuantityLocked(MissionModifier m)
		{
			return (m & (MissionModifier.Bulk | MissionModifier.Pristine | MissionModifier.Rush)) != 0;
		}

		public static int ChosenCount(int chosen, int offered)
		{
			return Math.Max(1, Math.Min(Math.Max(1, offered), chosen));
		}

		public static int ChosenShare(int whole, int chosen, int offered)
		{
			if (offered > 0 && chosen < offered)
			{
				return (int)Math.Round((double)whole * (double)Math.Max(0, chosen) / (double)offered, MidpointRounding.AwayFromZero);
			}
			return whole;
		}

		public static float RepScale(int chosen, int offered)
		{
			if (offered > 0 && chosen < offered)
			{
				return (float)Math.Max(0, chosen) / (float)offered;
			}
			return 1f;
		}

		public static string ModifierPrefix(MissionModifier m)
		{
			return (((m & MissionModifier.Bulk) != MissionModifier.None) ? "Bulk " : "") + (((m & MissionModifier.Pristine) != MissionModifier.None) ? "Pristine " : "") + (((m & MissionModifier.Rush) != MissionModifier.None) ? "Rush " : "");
		}

		public static int BulkGold(int normalTotal, int normalCount, int bulkCount)
		{
			if (normalCount <= 0)
			{
				return normalTotal;
			}
			return normalTotal / normalCount * bulkCount;
		}

		public static int ModifierGold(MissionModifier m)
		{
			return (((m & MissionModifier.Bulk) == 0) ? 1 : 2) * (((m & MissionModifier.Pristine) == 0) ? 1 : 2) * (((m & MissionModifier.Rush) == 0) ? 1 : 2) * (((m & MissionModifier.Fragile) == 0) ? 1 : 2);
		}

		public static int ModifierCapacity(MissionCategory c, MissionModifier m, bool origin)
		{
			return (((m & MissionModifier.Bulk) != MissionModifier.None) ? 3 : 0) + (((m & MissionModifier.Rush) != MissionModifier.None && ((c == MissionCategory.Industrial && !origin) || (c == MissionCategory.Luxury && origin))) ? 4 : 0);
		}

		public static float RushKnots(MissionCategory c)
		{
			if (c != MissionCategory.Luxury)
			{
				return 7.5f;
			}
			return 8f;
		}

		public static int RushDays(float missionDistance, float knots, float realDaySeconds)
		{
			return Mathf.RoundToInt(missionDistance / 10f / (knots * 1.852f * realDaySeconds / 3600f));
		}

		public static int WaterHintPercent(float health)
		{
			return Mathf.RoundToInt(100f - Mathf.Clamp(health, 0f, 100f));
		}

		public static bool BulkDoubles(int normalCount, int stock)
		{
			if (normalCount > 0)
			{
				return stock >= 2 * normalCount;
			}
			return false;
		}

		public static MissionModifier[] RollModifiers(MissionCategory[] categories, bool[] damageable, int level, Func<double> roll, bool[] doublable = null)
		{
			MissionModifier[] result = new MissionModifier[categories.Length];
			if (level < 3)
			{
				return result;
			}
			bool always = level >= 4;
			Give((from i in Of(MissionCategory.Staple, pristine: false)
				where doublable == null || doublable[i]
				select i).ToArray(), MissionModifier.Bulk);
			Give(Of(MissionCategory.ConsumerGoods, pristine: true), MissionModifier.Pristine);
			Give(Of(MissionCategory.Industrial, pristine: false), MissionModifier.Rush);
			int[] array = Of(MissionCategory.Luxury, pristine: false);
			int[] array2 = Of(MissionCategory.Luxury, pristine: true);
			if (!always)
			{
				Give(array2, MissionModifier.Pristine);
				Give(array, MissionModifier.Rush);
				return result;
			}
			if (array.Length == 0)
			{
				return result;
			}
			if (array2.Length == 0)
			{
				result[Pick(array)] |= MissionModifier.Rush;
				return result;
			}
			int pristine = Pick(array2);
			result[pristine] |= MissionModifier.Pristine;
			int[] array3 = array.Where((int i) => i != pristine).ToArray();
			result[(roll() < 0.5 || array3.Length == 0) ? pristine : Pick(array3)] |= MissionModifier.Rush;
			return result;
			bool Chance()
			{
				if (!always)
				{
					return roll() < 0.5;
				}
				return true;
			}
			void Give(int[] from, MissionModifier m)
			{
				if (from.Length != 0 && Chance())
				{
					result[Pick(from)] |= m;
				}
			}
			int[] Of(MissionCategory c, bool flag)
			{
				return (from i in Enumerable.Range(0, categories.Length)
					where categories[i] == c && (!flag || damageable[i])
					select i).ToArray();
			}
			int Pick(int[] from)
			{
				return from[Math.Min(from.Length - 1, (int)(roll() * (double)from.Length))];
			}
		}

		public static bool FragileGood(int good)
		{
			if (good != 20 && good != 34)
			{
				return good == 55;
			}
			return true;
		}

		public static float FragileDamage(float impact, float hullAdded)
		{
			return Math.Min(100f, Math.Max(0f, impact) + Math.Max(0f, hullAdded) * 250f);
		}

		public static int DamagePercent(float impact)
		{
			return Mathf.RoundToInt(Mathf.Clamp(impact, 0f, 100f));
		}

		public static float IntactFactor(float impact)
		{
			return (100f - Mathf.Clamp(impact, 0f, 100f)) / 100f;
		}

		public static int WarehouseCapacity(float portCapacity)
		{
			return Math.Max(1, (int)Math.Round(portCapacity, MidpointRounding.AwayFromZero)) + 100;
		}

		public static int PrefillSlots(int capacity)
		{
			return (int)Math.Round((double)capacity * 0.8, MidpointRounding.AwayFromZero);
		}

		public static bool WarehouseGood(int good, float[] production)
		{
			if (good > 0 && good < production.Length && production[good] > 0f)
			{
				return Category(good) != MissionCategory.None;
			}
			return false;
		}

		public static int WarehousePick(int[] counts, float[] production, bool[] stocked, int capacity, double roll)
		{
			int num = Math.Min(production.Length, Math.Min(counts.Length, stocked.Length));
			double num2 = 0.0;
			for (int i = 1; i < num; i++)
			{
				if (WarehouseGood(i, production))
				{
					num2 += (double)production[i];
				}
			}
			if (num2 <= 0.0)
			{
				return 0;
			}
			int num3 = 0;
			int result = 0;
			double num4 = double.MaxValue;
			double num5 = 0.0;
			bool flag = false;
			for (int j = 1; j < num; j++)
			{
				if (WarehouseGood(j, production) && stocked[j])
				{
					flag = true;
					double num6 = (double)counts[j] / ((double)production[j] / num2 * (double)capacity);
					if (num6 < 0.85 && num6 < num4)
					{
						num3 = j;
						num4 = num6;
					}
					if (num6 < 1.15)
					{
						num5 += (double)production[j];
						result = j;
					}
				}
			}
			if (!flag)
			{
				return 0;
			}
			if (num3 > 0)
			{
				return num3;
			}
			if (num5 <= 0.0)
			{
				return -1;
			}
			double num7 = roll * num5;
			for (int k = 1; k < num; k++)
			{
				if (WarehouseGood(k, production) && stocked[k] && !((double)counts[k] / ((double)production[k] / num2 * (double)capacity) >= 1.15))
				{
					num7 -= (double)production[k];
					if (num7 < 0.0)
					{
						return k;
					}
				}
			}
			return result;
		}

		public static int BookTier(string group)
		{
			switch (group)
			{
			default:
				return int.MaxValue;
			case "chronos":
				return 5;
			case "independent":
				return 4;
			case "small3":
			case "heavy2":
			case "regional":
			case "happy":
				return 3;
			case "small2":
			case "medium":
			case "heavy":
			case "shuttle":
				return 2;
			case "small":
				return 1;
			}
		}

		public static bool BookUnlocked(string group, int home, int[] reps)
		{
			if (group == "happy")
			{
				int[] array = reps;
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i] >= BookTier(group))
					{
						return true;
					}
				}
				return false;
			}
			if (group == "independent")
			{
				int num = 0;
				int[] array = reps;
				for (int i = 0; i < array.Length; i++)
				{
					if (array[i] >= 4)
					{
						num++;
					}
				}
				if (home >= 0)
				{
					return num > home;
				}
				return false;
			}
			if (home >= 0 && home < reps.Length)
			{
				return reps[home] >= BookTier(group);
			}
			return false;
		}

		public static bool BookReleases(int portLevel)
		{
			return portLevel > 0;
		}

		public static bool LevelRose(int[] before, int[] now)
		{
			if (before == null || now == null)
			{
				return false;
			}
			for (int i = 0; i < Math.Min(before.Length, now.Length); i++)
			{
				if (now[i] > before[i])
				{
					return true;
				}
			}
			return false;
		}

		public static bool BookCovers(string fg, int fh, string eg, int eh)
		{
			if (fg == "happy")
			{
				return BookTier(eg) >= BookTier(fg);
			}
			if (fg == "independent")
			{
				if (!(eg == "independent") || eh < fh)
				{
					if (fh == 0)
					{
						return eg == "chronos";
					}
					return false;
				}
				return true;
			}
			if (eg == "happy" || eg == "independent")
			{
				return false;
			}
			if (fh == eh)
			{
				return BookTier(fg) <= BookTier(eg);
			}
			return false;
		}

		public static bool RumorAccepted(int drink)
		{
			if (drink >= 2 && drink <= 13)
			{
				return drink != 9;
			}
			return false;
		}

		public static bool RumorBoatType(int drink)
		{
			if (drink >= 2)
			{
				return drink <= 8;
			}
			return false;
		}

		public static bool RumorLoadSize(int drink)
		{
			if (drink >= 2)
			{
				return drink <= 4;
			}
			return false;
		}

		public static double ReportPull(double percent, int ageDays, double perDay)
		{
			return percent * (1.0 + perDay * (double)Math.Max(0, ageDays));
		}

		public static bool ValidRoute(string group, int origin, int destination, int home, int originRegion, int destinationRegion, double distance, bool forEvent = false, int eventRegion = -1)
		{
			if (origin == destination || destination == 7 || destination == 33)
			{
				return false;
			}
			if (group == "chronos")
			{
				if ((origin != 21 || destination != home) && (origin != home || destination != 21))
				{
					if (origin != 21 && origin != home)
					{
						return destination == home;
					}
					return false;
				}
				return true;
			}
			if (destination == 21)
			{
				return false;
			}
			if (group == "happy")
			{
				return origin == 20 != (destination == 20);
			}
			if (group == "heavy")
			{
				if (origin != 19 && origin != 26 && origin != 28 && destination != 19 && destination != 26)
				{
					return destination == 28;
				}
				return true;
			}
			if (forEvent && (group == "independent" || (group == "regional" && eventRegion == home && destinationRegion == home)))
			{
				return true;
			}
			switch (group)
			{
			case "regional":
			case "independent":
				if (distance > 140.0)
				{
					if (!(group == "independent"))
					{
						return originRegion == home != (destinationRegion == home);
					}
					return true;
				}
				return false;
			case "shuttle":
				return (origin >= 22 && origin <= 25) != (destination >= 22 && destination <= 25);
			default:
				return true;
			}
		}

		public static double Clamp(double x, double lo, double hi)
		{
			return Math.Max(lo, Math.Min(hi, x));
		}

		public static int Round(double x)
		{
			return checked((int)Math.Round(x, MidpointRounding.ToEven));
		}

		public static bool StaleSave(double savedHour, double gameHour)
		{
			if (savedHour > 0.0)
			{
				return Math.Abs(savedHour - gameHour) > 0.01;
			}
			return false;
		}

		public static bool ModItem(int prefabIndex)
		{
			if (prefabIndex >= 640)
			{
				return prefabIndex <= 646;
			}
			return false;
		}

		internal static double NormalizePenaltyResidue(double value)
		{
			if (!(value < 0.0) || !(value >= -1E-08))
			{
				return value;
			}
			return 0.0;
		}

		internal static int SplitPenalty(double penalty, out double remainder)
		{
			int num = checked((int)Math.Floor(penalty + 1E-08));
			remainder = NormalizePenaltyResidue(penalty - (double)num);
			return num;
		}

		internal static int RepaymentPenalty(double penalty, int reputation, out double remainder)
		{
			if (double.IsNaN(penalty) || penalty < 0.0)
			{
				throw new ArgumentOutOfRangeException("penalty");
			}
			if (penalty >= (double)reputation)
			{
				remainder = 0.0;
				return Math.Max(0, reputation);
			}
			return SplitPenalty(penalty, out remainder);
		}

		public static double CreditLimit(int level)
		{
			double[] array = new double[9] { 0.0, 10000.0, 20000.0, 40000.0, 60000.0, 80000.0, 100000.0, 200000.0, 400000.0 };
			if (level < 9)
			{
				return array[Math.Max(0, level)];
			}
			return double.PositiveInfinity;
		}

		public static double Interest(int level)
		{
			return InterestByLevel[Math.Max(0, Math.Min(10, level))];
		}

		public static double LoanCrateRep(int level, int required, double distance, double range)
		{
			if (level < 1 || required <= 0 || !(distance > 0.0))
			{
				return 0.0;
			}
			bool flag = double.IsPositiveInfinity(CreditLimit(level));
			return Math.Min((flag ? 0.002 : 0.005) * (double)required, (flag ? 0.04 : 0.1) * Math.Min(distance, Math.Max(0.0, range)));
		}

		public static int BottomryRep(int level, int required, double payoutUnits, int startDay, int dueDay, int day)
		{
			if (level < 1 || required <= 0 || !(payoutUnits > 0.0) || day > dueDay || day <= startDay)
			{
				return 0;
			}
			double num = CreditLimit(level);
			bool flag = double.IsPositiveInfinity(num);
			return Round((flag ? 0.05 : 0.1) * (double)required * Math.Min(1.0, payoutUnits / (flag ? CreditLimit(8) : num)));
		}

		public static Settlement Settle(double debt, int proceeds, double lenderRate, double saleRate)
		{
			if (!(lenderRate > 0.0) || !(saleRate > 0.0))
			{
				throw new ArgumentOutOfRangeException("lenderRate");
			}
			if (lenderRate == saleRate)
			{
				return new Settlement
				{
					Payout = (int)Math.Floor(Math.Max(0.0, (double)proceeds - debt)),
					Shortfall = (int)Math.Ceiling(Math.Max(0.0, debt - (double)proceeds))
				};
			}
			double num = debt * saleRate / lenderRate;
			return new Settlement
			{
				Payout = (((double)proceeds >= num) ? ((int)Math.Floor((double)proceeds - num + 1E-08)) : 0),
				Shortfall = (((double)proceeds < num) ? ((int)Math.Ceiling(debt - (double)proceeds * lenderRate / saleRate - 1E-08)) : 0)
			};
		}

		public static double NewlyUnpaid(int before, int after, double rate)
		{
			return Math.Max(0.0, Math.Max(0.0, 0.0 - (double)after) - Math.Max(0.0, 0.0 - (double)before)) / rate;
		}

		public static double BottomryRate(int level)
		{
			return (new double[11]
			{
				0.0, 0.35, 0.35, 0.3, 0.25, 0.2, 0.17, 0.14, 0.1, 0.05,
				0.03
			})[Math.Max(0, Math.Min(10, level))];
		}

		public static int BottomryTerm(int level)
		{
			if (level >= 1)
			{
				if (level > 3)
				{
					if (level > 6)
					{
						return 30;
					}
					return 25;
				}
				return 20;
			}
			return 0;
		}

		public static double BottomryLateRate(double baseRate, int daysLate)
		{
			return baseRate * (1.0 + 0.1 * (double)Math.Max(0, Math.Min(10, daysLate)));
		}

		public static int BottomryOwed(int principal, double rate)
		{
			return Round((double)principal * (1.0 + rate));
		}

		public static int BottomryRemote(int principal, double rate)
		{
			return Round((double)principal * (1.0 + 2.0 * rate));
		}

		public static int BottomryBoxOwed(int principal, double rate)
		{
			return Round((double)principal * (1.0 + rate + 0.1));
		}

		public static double RentalValue(int price, double goldRate, double localRate)
		{
			return (double)price / goldRate * localRate;
		}

		public static int RentalDeposit(double value)
		{
			return Round(0.2 * value);
		}

		public static int RentalDaily(double value)
		{
			return Round(0.05 * value);
		}

		public static int RentalDays(int startDay, int day, int charges)
		{
			int val = day - startDay - 20 * charges;
			if (charges != 0)
			{
				return Math.Max(0, val);
			}
			return Math.Max(1, val);
		}

		public static int NextRentDay(int startDay, int charges)
		{
			return startDay + 20 * (charges + 1);
		}

		public static int ShipyardBase(int price)
		{
			return (int)Math.Round((float)price * 3.5f);
		}

		public static int CleaningFee(int price, float rate)
		{
			return (int)Math.Round((float)ShipyardBase(price) * rate * 2.25f);
		}

		public static int RepairFee(int price, float rate, float hullDamage, float capacity)
		{
			return (int)Math.Round((float)ShipyardBase(price) * rate * hullDamage * capacity * 0.1f);
		}

		public static int SailRepairFee(IEnumerable<SailHoles> sails, float rate, float share)
		{
			float num = 0f;
			if (sails != null)
			{
				foreach (SailHoles sail in sails)
				{
					num += sail.Price * rate * share * sail.Hole / (Math.Max(1f, sail.Area) + sail.Full);
				}
			}
			return (int)Math.Round(num);
		}

		public static int CrewSalePrice(int price, double condition)
		{
			if (price > 0)
			{
				return (int)Math.Floor((double)price * Math.Max(0.0, Math.Min(1.0, condition)));
			}
			return price;
		}

		public static int OfficePrice(int housePrice)
		{
			return Math.Max(1, (int)Math.Ceiling((double)housePrice * 0.1));
		}

		public static float ClerkTurn(float yaw, int dir, float seconds)
		{
			float num = (yaw + (float)Math.Sign(dir) * 60f * Math.Max(0f, seconds)) % 360f;
			if (!(num < 0f))
			{
				return num;
			}
			return num + 360f;
		}

		public static Quaternion ClerkFacing(float yaw)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			double num = (double)yaw * Math.PI / 360.0;
			return new Quaternion(0f, (float)Math.Sin(num), 0f, (float)Math.Cos(num));
		}

		public static string ClerkMoveHint(string place, string cancel, string turnLeft, string turnRight)
		{
			return "Aim at where clerk stand. Left click" + ((place != null) ? (" or " + place) : "") + " to place. " + ((turnLeft != null && turnRight != null) ? (turnLeft + "/" + turnRight + " to rotate. ") : ((turnLeft != null) ? (turnLeft + " to rotate. ") : ((turnRight != null) ? (turnRight + " to rotate. ") : ""))) + "Right click" + ((cancel != null) ? (" or " + cancel) : "") + " to cancel.";
		}

		public static bool WharfHouse(int house)
		{
			if (house != 204 && house != 205)
			{
				return house == 206;
			}
			return true;
		}

		public static int FleetLeavePay(int hullPrice, bool kept)
		{
			if (!kept)
			{
				return (int)Math.Floor((double)hullPrice * 0.8);
			}
			return 0;
		}

		public static int ClerkSalary(double dailyRate)
		{
			return Math.Max(1, (int)Math.Round(166.66666666666666 * dailyRate));
		}

		public static bool OfficeAbsent(bool inStock, float production)
		{
			if (!inStock)
			{
				return !(production > 0f);
			}
			return false;
		}

		public static string Tally(string tally, int index, int add)
		{
			Dictionary<int, int> dictionary = ReadTally(tally);
			dictionary[index] = (dictionary.TryGetValue(index, out var value) ? value : 0) + add;
			CultureInfo ic = CultureInfo.InvariantCulture;
			return string.Join(" ", dictionary.Select((KeyValuePair<int, int> kv) => kv.Key.ToString(ic) + ":" + kv.Value.ToString(ic)).ToArray());
		}

		public static bool WharfBerthFor(bool fleetShip, int destination, int origin, int port, IEnumerable<int> wharfPorts)
		{
			if (fleetShip && destination < 0 && origin == port && port >= 0 && wharfPorts != null)
			{
				return wharfPorts.Contains(port);
			}
			return false;
		}

		public static int FreeAtWharf(IList<string> lines, IList<string[]> changed = null)
		{
			int num = 0;
			int num2 = 0;
			while (lines != null && num2 < lines.Count)
			{
				string text = lines[num2];
				int num3 = text?.IndexOf(": ", StringComparison.Ordinal) ?? (-1);
				if (num3 > 0 && Array.IndexOf(WharfFreeLines, text.Substring(num3 + 2)) >= 0 && int.TryParse(text.Substring(0, num3), NumberStyles.Integer, CultureInfo.InvariantCulture, out var result) && result != 0)
				{
					string text2 = "0: " + text.Substring(num3 + 2);
					num += result;
					lines[num2] = text2;
					changed?.Add(new string[2] { text, text2 });
				}
				num2++;
			}
			return num;
		}

		public static string OrderTotalLine(int total, string coin)
		{
			if (total >= 0)
			{
				return "TOTAL: " + total + " " + coin;
			}
			return "TOTAL: " + -total + " " + coin + " refund";
		}

		public static Dictionary<int, int> ReadTally(string tally)
		{
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			if (string.IsNullOrEmpty(tally))
			{
				return dictionary;
			}
			CultureInfo invariantCulture = CultureInfo.InvariantCulture;
			NumberStyles style = NumberStyles.Integer;
			string[] array = tally.Split(new char[1] { ' ' });
			foreach (string text in array)
			{
				int num = text.IndexOf(':');
				if (num > 0 && int.TryParse(text.Substring(0, num), style, invariantCulture, out var result) && int.TryParse(text.Substring(num + 1), style, invariantCulture, out var result2))
				{
					dictionary[result] = (dictionary.TryGetValue(result, out var value) ? value : 0) + result2;
				}
			}
			return dictionary;
		}

		public static int Most(string tally, out int count)
		{
			count = 0;
			int result = -1;
			foreach (KeyValuePair<int, int> item in ReadTally(tally))
			{
				if (item.Value > count)
				{
					count = item.Value;
					result = item.Key;
				}
			}
			return result;
		}

		public static FxExchange FlatExchange(double[] smooth, double[] live, int sold, int bought, int amount, bool requestBuy)
		{
			FxExchange result = new FxExchange
			{
				Error = "Choose currencies and an amount"
			};
			if (smooth == null || live == null || smooth.Length != 4 || live.Length != 4 || sold < 0 || sold > 3 || bought < 0 || bought > 3 || sold == bought || amount <= 0)
			{
				return result;
			}
			double num = smooth[sold];
			double num2 = smooth[bought];
			if (!(num > 0.0) || !(num2 > 0.0))
			{
				result.Error = "Currency runs out!";
				return result;
			}
			double num3 = (requestBuy ? Math.Ceiling((double)amount * num / num2 - 1E-09) : ((double)amount));
			if (num3 > 2147483647.0)
			{
				result.Error = "Amount exceeds wallet limit";
				return result;
			}
			double num4 = num3 * num2 / num;
			double num5 = Math.Floor(num4 + 1E-09);
			if (num5 < 1.0)
			{
				result.Error = "Amount too small";
				return result;
			}
			if (num5 > 2147483647.0)
			{
				result.Error = "Amount exceeds wallet limit";
				return result;
			}
			result.Valid = true;
			result.Error = null;
			result.Sold = (int)num3;
			result.Received = (int)num5;
			result.GrossReceived = num4;
			result.Fee = 0.0;
			result.SellRate = live[sold];
			result.BuyRate = live[bought];
			return result;
		}

		public static float PathLength(IList<Vector2> p)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			for (int i = 1; i < p.Count; i++)
			{
				float num2 = num;
				Vector2 val = p[i] - p[i - 1];
				num = num2 + ((Vector2)(ref val)).magnitude;
			}
			return num;
		}

		public static Vector2 PathAt(IList<Vector2> p, float s)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 1; i < p.Count; i++)
			{
				Vector2 val = p[i] - p[i - 1];
				float magnitude = ((Vector2)(ref val)).magnitude;
				if (s <= magnitude || i == p.Count - 1)
				{
					return Vector2.Lerp(p[i - 1], p[i], (magnitude > 0f) ? Mathf.Clamp01(s / magnitude) : 0f);
				}
				s -= magnitude;
			}
			if (p.Count <= 0)
			{
				return Vector2.zero;
			}
			return p[p.Count - 1];
		}

		public static List<Vector2> PathFrom(IList<Vector2> p, float s0)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			List<Vector2> list = new List<Vector2> { PathAt(p, s0) };
			float num = 0f;
			for (int i = 1; i < p.Count; i++)
			{
				float num2 = num;
				Vector2 val = p[i] - p[i - 1];
				num = num2 + ((Vector2)(ref val)).magnitude;
				if (num > s0 + 0.01f)
				{
					list.Add(p[i]);
				}
			}
			return list;
		}

		public static float PathAlong(IList<Vector2> p, float x, float z)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MaxValue;
			float result = 0f;
			float num2 = 0f;
			for (int i = 1; i < p.Count; i++)
			{
				float x2 = p[i - 1].x;
				float y = p[i - 1].y;
				float num3 = p[i].x - x2;
				float num4 = p[i].y - y;
				float num5 = num3 * num3 + num4 * num4;
				float num6 = ((num5 > 0f) ? Mathf.Clamp01(((x - x2) * num3 + (z - y) * num4) / num5) : 0f);
				float num7 = x2 + num3 * num6 - x;
				float num8 = y + num4 * num6 - z;
				float num9 = num7 * num7 + num8 * num8;
				float num10 = (float)Math.Sqrt(num5);
				if (num9 < num)
				{
					num = num9;
					result = num2 + num6 * num10;
				}
				num2 += num10;
			}
			return result;
		}

		public static List<int> Doubled(IList<int> kinds, IList<Vector3> places, IList<Quaternion> turns, IList<Vector3> scales)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			List<int> list = new List<int>();
			List<int> list2 = new List<int>();
			for (int i = 0; i < places.Count; i++)
			{
				bool flag = false;
				foreach (int item in list2)
				{
					if (kinds[item] != kinds[i])
					{
						continue;
					}
					Vector3 val = places[item] - places[i];
					if (((Vector3)(ref val)).magnitude > 0.05f)
					{
						continue;
					}
					val = scales[item] - scales[i];
					if (!(((Vector3)(ref val)).magnitude > 0.005f))
					{
						float num = Math.Min(1f, Math.Abs(Quaternion.Dot(turns[item], turns[i])));
						if (2f * (float)Math.Acos(num) * 57.29578f <= 1f)
						{
							flag = true;
							break;
						}
					}
				}
				if (flag)
				{
					list.Add(i);
				}
				else
				{
					list2.Add(i);
				}
			}
			return list;
		}

		public static float PathDistance(IList<Vector2> p, float x, float z)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			float num = float.MaxValue;
			for (int i = 1; i < p.Count; i++)
			{
				float x2 = p[i - 1].x;
				float y = p[i - 1].y;
				float num2 = p[i].x - x2;
				float num3 = p[i].y - y;
				float num4 = num2 * num2 + num3 * num3;
				float num5 = ((num4 > 0f) ? Mathf.Clamp01(((x - x2) * num2 + (z - y) * num3) / num4) : 0f);
				float num6 = x2 + num2 * num5 - x;
				float num7 = y + num3 * num5 - z;
				num = Math.Min(num, num6 * num6 + num7 * num7);
			}
			if (num != float.MaxValue)
			{
				return (float)Math.Sqrt(num);
			}
			return num;
		}

		public static float PathWeight(float distance)
		{
			float num = distance - 0.9f;
			float num2 = ((num <= 0f) ? 1f : Mathf.Clamp01(1f - num / 0.9f));
			return num2 * num2 * (3f - 2f * num2);
		}

		public static bool PaintCell(float[,,] a, int y, int x, int li, float w)
		{
			float num = a[y, x, li];
			if (w <= num + 0.004f)
			{
				return false;
			}
			float num2 = ((num < 0.999f) ? ((1f - w) / (1f - num)) : 0f);
			int length = a.GetLength(2);
			for (int i = 0; i < length; i++)
			{
				a[y, x, i] = ((i == li) ? w : (a[y, x, i] * num2));
			}
			return true;
		}

		public static void TakeOff(float[,,] a, int y, int x, int li, float o, float[] mix)
		{
			int length = a.GetLength(2);
			float num = a[y, x, li] - o;
			if (num <= 0f)
			{
				return;
			}
			float num2 = 0f;
			for (int i = 0; i < length; i++)
			{
				if (i != li)
				{
					num2 += mix[i];
				}
			}
			for (int j = 0; j < length; j++)
			{
				if (j != li)
				{
					a[y, x, j] += ((num2 > 0f) ? (num * mix[j] / num2) : (num / (float)Math.Max(1, length - 1)));
				}
			}
			a[y, x, li] = o;
		}

		public static float[,,] FinerGrid(float[,,] a)
		{
			int length = a.GetLength(0);
			int length2 = a.GetLength(2);
			int num = length * 2;
			float[,,] array = new float[num, num, length2];
			for (int i = 0; i < num; i++)
			{
				float num2 = ((float)i + 0.5f) * 0.5f - 0.5f;
				int num3 = Math.Min(length - 1, Math.Max(0, (int)Math.Floor(num2)));
				int num4 = Math.Min(length - 1, num3 + 1);
				float num5 = Mathf.Clamp01(num2 - (float)num3);
				for (int j = 0; j < num; j++)
				{
					float num6 = ((float)j + 0.5f) * 0.5f - 0.5f;
					int num7 = Math.Min(length - 1, Math.Max(0, (int)Math.Floor(num6)));
					int num8 = Math.Min(length - 1, num7 + 1);
					float num9 = Mathf.Clamp01(num6 - (float)num7);
					float num10 = (1f - num9) * (1f - num5);
					float num11 = num9 * (1f - num5);
					float num12 = (1f - num9) * num5;
					float num13 = num9 * num5;
					for (int k = 0; k < length2; k++)
					{
						array[i, j, k] = a[num3, num7, k] * num10 + a[num3, num8, k] * num11 + a[num4, num7, k] * num12 + a[num4, num8, k] * num13;
					}
				}
			}
			return array;
		}

		public static bool[] PickDrawn(IList<double> distance, IList<bool> drawn, IList<bool> inSight, int pool)
		{
			int count = distance.Count;
			int num = 0;
			int num2 = 0;
			bool[] array = new bool[count];
			for (int i = 0; i < count; i++)
			{
				if (drawn[i])
				{
					num2++;
					if (inSight[i])
					{
						array[i] = true;
						num++;
					}
				}
			}
			int num3 = Math.Max(0, pool - num);
			int num4 = Math.Max(0, pool - num2);
			foreach (int item in (from index in Enumerable.Range(0, count)
				where !drawn[index] || !inSight[index]
				orderby distance[index]
				select index).ThenBy((int result) => result))
			{
				if (num3 == 0)
				{
					break;
				}
				if (drawn[item])
				{
					array[item] = true;
					num3--;
				}
				else if (num4 > 0)
				{
					array[item] = true;
					num3--;
					num4--;
				}
				else if (!inSight[item])
				{
					array[item] = true;
					num3--;
				}
			}
			return array;
		}

		public static int TraderPool(string key)
		{
			if (key == null)
			{
				return 0;
			}
			if (key.StartsWith("stock-"))
			{
				int.TryParse(key.Substring("stock-".Length), out var result);
				if (result != 10)
				{
					if (HullClass(result) != 0)
					{
						if (HullClass(result) != 2)
						{
							return 2;
						}
						return 1;
					}
					return 4;
				}
				return 5;
			}
			if (!key.StartsWith("small-") && !(key == "ffl-small") && !(key == "medium-alankh"))
			{
				return 1;
			}
			return 2;
		}

		public static string TraderKey(string plan, int hull)
		{
			return plan ?? ("stock-" + hull);
		}

		public static int TraderLantern(int hull)
		{
			switch (hull)
			{
			default:
				return 110;
			case 70:
			case 80:
			case 90:
				return 111;
			case 40:
			case 50:
				return 114;
			}
		}

		public static int TraderLantern(string plan, int hull)
		{
			switch (plan)
			{
			default:
				return TraderLantern(hull);
			case "shuttle":
			case "ffl-small":
			case "indep-junk-3":
				return 134;
			case "happy":
				return 111;
			}
		}

		public static int OutfitKind(string material)
		{
			if (material == null)
			{
				return -1;
			}
			if (!Has("AlAnkh"))
			{
				if (!Has("East Swamp"))
				{
					if (!Has("East"))
					{
						if (!Has("Medi"))
						{
							if (!Has("Senna"))
							{
								if (!Has("Generic"))
								{
									return -1;
								}
								return 5;
							}
							return 4;
						}
						return 2;
					}
					return 1;
				}
				return 3;
			}
			return 0;
			bool Has(string s)
			{
				return material.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0;
			}
		}

		public static int OutfitKind(IEnumerable<string> partMaterials)
		{
			int[] array = new int[6];
			foreach (string partMaterial in partMaterials)
			{
				int num = OutfitKind(partMaterial);
				if (num >= 0)
				{
					array[num]++;
				}
			}
			int num2 = -1;
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] > 0 && (num2 < 0 || array[i] > array[num2]))
				{
					num2 = i;
				}
			}
			return num2;
		}

		public static int HelmsmanStyle(string group, int home, bool ffl)
		{
			switch (group)
			{
			case "independent":
				return -1;
			case "chronos":
				return 2;
			case "happy":
				return 1;
			default:
				if (group == "small" && ffl)
				{
					return 3;
				}
				if (home < 0 || home >= 3)
				{
					return -1;
				}
				return home;
			}
		}

		public static string EvenRows(string line, Func<string, float> width)
		{
			string[] array = line.Split(new char[1] { ' ' });
			if (array.Length < 2)
			{
				return line;
			}
			string result = line;
			float num = float.MaxValue;
			for (int i = 1; i < array.Length; i++)
			{
				string text = string.Join(" ", array, 0, i);
				string text2 = string.Join(" ", array, i, array.Length - i);
				float num2 = Math.Max(width(text), width(text2));
				if (num2 < num)
				{
					num = num2;
					result = text + "\n" + text2;
				}
			}
			return result;
		}

		public static int PickLine(int count, int last, double roll)
		{
			if (count <= 0)
			{
				return -1;
			}
			if (count == 1 || last < 0 || last >= count)
			{
				return Math.Max(0, Math.Min(count - 1, (int)(roll * (double)count)));
			}
			int num = Math.Max(0, Math.Min(count - 2, (int)(roll * (double)(count - 1))));
			if (num < last)
			{
				return num;
			}
			return num + 1;
		}

		public static int PickOutfit(int style, IList<int> kinds, ICollection<int> worn, double roll)
		{
			List<int> all = Enumerable.Range(0, kinds.Count).ToList();
			List<int> list = ((style >= 0) ? Free((int i) => kinds[i] == style) : new List<int>());
			if (list.Count == 0 && style >= 0)
			{
				list = Free((int i) => kinds[i] == 5);
			}
			if (list.Count == 0)
			{
				list = Free((int i) => true);
			}
			if (list.Count == 0)
			{
				list = all;
			}
			if (list.Count == 0)
			{
				return -1;
			}
			return list[Math.Max(0, Math.Min(list.Count - 1, (int)(roll * (double)list.Count)))];
			List<int> Free(Func<int, bool> fits)
			{
				return all.Where((int i) => fits(i) && !worn.Contains(i)).ToList();
			}
		}

		public static string TraderPlan(string group, int home, bool ffl, int independentRank, int smallPlace)
		{
			string text = ((home >= 0 && home < 3) ? RegionNames[home] : null);
			switch (group)
			{
			case "small":
				if (!ffl)
				{
					if (text == null || (smallPlace != 5 && smallPlace != 6))
					{
						return null;
					}
					return "small-" + text;
				}
				return "ffl-small";
			case "medium":
				if (text == null)
				{
					return null;
				}
				return "medium-" + text;
			case "happy":
			case "heavy":
			case "shuttle":
				return group;
			case "chronos":
				if (home != 15)
				{
					return null;
				}
				return "chronos-brig";
			case "independent":
				if (independentRank < 0 || independentRank >= 9)
				{
					return null;
				}
				return "indep-" + ((independentRank / 3 == 0) ? "sanbuq" : ((independentRank / 3 == 1) ? "junk" : "brig")) + "-" + (independentRank % 3 + 1);
			default:
				return null;
			}
		}

		public static bool InStormRain(double distance, double radius, double range, double border = 0.33)
		{
			return distance <= radius + border * Math.Max(0.0, range);
		}

		public static double TiltEase(int hullClass, bool held)
		{
			if (held)
			{
				return hullClass switch
				{
					1 => 1.5, 
					0 => 1.0, 
					_ => 2.0, 
				};
			}
			return 0.25;
		}

		public static double HeightEase(bool held)
		{
			return held ? 1 : 0;
		}

		public static double CargoSink(double mass, double forceMultiplier)
		{
			if (!(mass > 0.0) || !(forceMultiplier > 0.0))
			{
				return 0.0;
			}
			return mass / (1000.0 * forceMultiplier);
		}

		public static bool WaitHeld(bool waitingInPort, bool atItsPlace)
		{
			if (waitingInPort)
			{
				return !atItsPlace;
			}
			return false;
		}

		public static double TrimOut(double awa, double sheetedIn)
		{
			return Clamp(Math.Abs(awa) / 2.0, sheetedIn, 80.0);
		}

		public static bool JunkSquare(int prefab)
		{
			if (prefab < 27 || prefab > 29)
			{
				if (prefab >= 100)
				{
					return prefab <= 103;
				}
				return false;
			}
			return true;
		}

		public static double PushShare(double attack)
		{
			return Math.Max(0.3, Math.Sin(Clamp(attack, -90.0, 90.0) * Math.PI / 180.0));
		}

		public static bool GooseTurns(bool on, double awa)
		{
			if (!on)
			{
				return Math.Abs(awa) >= 170.0;
			}
			return Math.Abs(awa) < 165.0;
		}

		public static bool GooseHeld(bool on, double awa, double heldFor, bool atSea)
		{
			if (atSea)
			{
				if (!GooseTurns(on, awa) || !(heldFor >= 7.0))
				{
					return on;
				}
				return !on;
			}
			return false;
		}

		public static int GooseSide(int order, int side)
		{
			if (order % 2 != 0)
			{
				return -side;
			}
			return side;
		}

		public static double SquareBraceMost(bool allSquare)
		{
			if (!allSquare)
			{
				return 70.0;
			}
			return 80.0;
		}

		public static double SquareBrace(double awa, bool allSquare = false)
		{
			return Clamp(106.0 - Math.Abs(awa), 0.0, SquareBraceMost(allSquare));
		}

		public static double SquareAttack(double awa, double brace)
		{
			return Math.Abs(awa) + brace - 90.0;
		}

		public static bool SquareTurns(bool set, double awa)
		{
			if (!set)
			{
				return Math.Abs(awa) >= 36.0;
			}
			return Math.Abs(awa) < 33.0;
		}

		public static bool SquareSet(bool set, double awa, double heldFor, bool atSea)
		{
			if (atSea)
			{
				if (!SquareTurns(set, awa) || !(heldFor >= 7.0))
				{
					return set;
				}
				return !set;
			}
			return false;
		}

		public static bool SquareAtApproach(double awa)
		{
			return Math.Abs(awa) >= 36.0;
		}

		public static bool SquareSet(bool set, double awa, double heldFor, bool atSea, bool allSquare)
		{
			if (!allSquare)
			{
				return SquareSet(set, awa, heldFor, atSea);
			}
			return true;
		}

		public static bool AllSquare(IEnumerable<int> kinds)
		{
			if (kinds.Any())
			{
				return kinds.All((int k) => k == 3);
			}
			return false;
		}

		public static bool SquaresKept(IEnumerable<int> kinds)
		{
			if (kinds.Contains(3))
			{
				return !kinds.Contains(2);
			}
			return false;
		}

		public static bool SailsOut(bool allSquare, bool underWay, bool berthed)
		{
			if (!underWay)
			{
				if (allSquare)
				{
					return !berthed;
				}
				return false;
			}
			return true;
		}

		public static bool FleetSailRefused(string sailName)
		{
			return sailName?.StartsWith("Fisherman's ", StringComparison.Ordinal) ?? false;
		}

		public static bool SidePast(int side, double wind, double line)
		{
			double num = (double)(-side) * wind;
			if (side != 0 && num >= line + 5.0)
			{
				return num <= 175.0;
			}
			return false;
		}

		public static int SailSideHeld(int side, double wind, double line, double heldFor)
		{
			if (!SidePast(side, wind, line) || !(heldFor >= 7.0))
			{
				return side;
			}
			return -side;
		}

		public static int Leeward(double wind)
		{
			if (!(wind >= 0.0))
			{
				return -1;
			}
			return 1;
		}

		public static double TraderStrength(double strength)
		{
			return 0.75 + 0.5 * Clamp((strength - 7.0) / 14.0, 0.0, 1.0);
		}

		public static double TraderCourse(double courseCos)
		{
			double num = Math.Acos(Clamp(courseCos, -1.0, 1.0)) * 180.0 / Math.PI;
			int num2 = Math.Min((int)(num / 45.0), TraderCourseFactor.Length - 2);
			return TraderCourseFactor[num2] + (TraderCourseFactor[num2 + 1] - TraderCourseFactor[num2]) * (num - (double)(45 * num2)) / 45.0;
		}

		public static double TraderSpeed(double speed, double strength, double courseCos)
		{
			return speed * TraderStrength(strength) * TraderCourse(courseCos);
		}

		public static double TripPlace(double trip, double remaining, double length)
		{
			if (!(trip > 0.0) || !(length > 0.0))
			{
				return 0.0;
			}
			return length * Clamp(1.0 - remaining / trip, 0.0, 1.0);
		}

		public static double TripRemaining(double trip, double place, double length)
		{
			if (!(length > 0.0))
			{
				return 0.0;
			}
			return trip * Clamp(1.0 - place / length, 0.0, 1.0);
		}

		public static int TraderHull(string group, int home, int independentRank)
		{
			switch (group)
			{
			case "small":
				return home switch
				{
					2 => 40, 
					0 => 10, 
					_ => 90, 
				};
			case "medium":
			case "regional":
				return home switch
				{
					2 => 50, 
					0 => 20, 
					_ => 80, 
				};
			case "happy":
			case "heavy":
				return 50;
			case "shuttle":
				return 80;
			case "independent":
				if (independentRank / 3 != 0)
				{
					if (independentRank / 3 != 1)
					{
						return 50;
					}
					return 80;
				}
				return 20;
			case "chronos":
				return home switch
				{
					9 => 70, 
					0 => 30, 
					_ => 50, 
				};
			default:
				return -1;
			}
		}

		public static int HullClass(int hull)
		{
			switch (hull)
			{
			default:
				return 1;
			case 30:
			case 70:
				return 2;
			case 10:
			case 40:
			case 90:
				return 0;
			}
		}

		public static int BerthClass(string size)
		{
			if (!(size == "small"))
			{
				if (!(size == "large"))
				{
					return 1;
				}
				return 2;
			}
			return 0;
		}

		public static double StairsAt(double z)
		{
			if (z <= stairZ[0])
			{
				return stairY[0];
			}
			for (int i = 1; i < stairZ.Length; i++)
			{
				if (z <= stairZ[i])
				{
					return stairY[i - 1] + (stairY[i] - stairY[i - 1]) * (z - stairZ[i - 1]) / (stairZ[i] - stairZ[i - 1]);
				}
			}
			return stairY[stairY.Length - 1];
		}

		public static double CabinFront(double height)
		{
			double num = 0.87 + height / 2.0;
			if (num <= stairY[0])
			{
				return 6.62;
			}
			for (int i = 1; i < stairZ.Length; i++)
			{
				if (num <= stairY[i])
				{
					return stairZ[i - 1] + (stairZ[i] - stairZ[i - 1]) * (num - stairY[i - 1]) / (stairY[i] - stairY[i - 1]);
				}
			}
			return 8.4;
		}

		public static double CabinCargoZ(double length, double height)
		{
			return Math.Max(CabinFront(height) - length / 2.0, 2.1 + length / 2.0);
		}

		public static bool FrontDeckFits(double across, double along)
		{
			double num = 8.8 + along;
			double num2 = Math.Floor((across / 2.0 + 0.001) / 0.2) * 0.2;
			for (int i = 0; 8.96 + (double)i * 0.2 <= num + 0.001; i++)
			{
				if (i >= frontDeckHalf.Length || frontDeckHalf[i] < num2 - 1E-06)
				{
					return false;
				}
			}
			return true;
		}

		public static bool FrontDeckPlace(double across, double along, out bool turned, out double z)
		{
			turned = false;
			z = 0.0;
			if (FrontDeckFits(across, along))
			{
				z = 8.8 + along / 2.0;
				return true;
			}
			if (FrontDeckFits(along, across))
			{
				turned = true;
				z = 8.8 + across / 2.0;
				return true;
			}
			return false;
		}

		public static bool BerthFits(double berthLength, double berthBeam, double hullLength, double hullBeam)
		{
			if (hullLength <= berthLength + 0.05)
			{
				return hullBeam <= berthBeam + 0.05;
			}
			return false;
		}

		public static int PickBerth(IList<int> classes, IList<bool> taken, int hullClass)
		{
			int num = -1;
			for (int i = 0; i < classes.Count; i++)
			{
				if (!taken[i] && classes[i] >= hullClass && (num < 0 || classes[i] < classes[num]))
				{
					num = i;
				}
			}
			return num;
		}

		public static double LaneShare(int id)
		{
			return (((double)id * 0.6180339887498949 + 0.5) % 1.0 * 2.0 - 1.0) * 0.9;
		}

		public static double OceanLerp(double distance)
		{
			if (!(distance >= 999999.0))
			{
				return Clamp((distance - 1500.0) / 2500.0, 0.0, 1.0);
			}
			return 0.0;
		}

		public static double HorizonDrop(double distance, double cameraHeight, double emerged = 1500.0)
		{
			return Math.Max((distance * distance / 1031324.0 - 2.0 * cameraHeight) * Clamp((distance - emerged) / (emerged * 1.25), 0.0, 1.0), -20.0);
		}

		public static bool LanternsLit(double localHour)
		{
			if (!(localHour > 16.5))
			{
				return localHour < 7.5;
			}
			return true;
		}

		public static bool LanternsLit(double localHour, bool inStorm)
		{
			if (!inStorm)
			{
				return LanternsLit(localHour);
			}
			return true;
		}

		public static bool CopySolid(double speed)
		{
			return speed <= 15.0;
		}

		public static double SailingSpeed(double realSpeed, double clock)
		{
			if (!(clock > 0.0))
			{
				return 0.0;
			}
			return realSpeed / clock;
		}

		public static double ClothWorldScale(double original, double clock)
		{
			if (!(clock > 1.0))
			{
				return original;
			}
			return original / clock;
		}

		public static double TurnRate(int hullClass)
		{
			return (double)(hullClass switch
			{
				1 => 5, 
				0 => 8, 
				_ => 4, 
			}) * 1.2;
		}

		public static double LegHalfWidth(double fromBerth, double room, double beam)
		{
			return Math.Max(0.0, Math.Min(20.0 * Clamp((fromBerth - 10.0) / 40.0, 0.0, 1.0), room - beam / 2.0 - 3.0));
		}

		public static double TurnNeed(double length, double beam)
		{
			return Math.Sqrt(length * length + beam * beam) / 2.0 + 3.0;
		}

		public static bool TurnRoom(double room, double left, double right, double length, double beam)
		{
			double num = TurnNeed(length, beam);
			if (room >= num && left >= num)
			{
				return right >= num;
			}
			return false;
		}

		public static double TurnSlow(double angle)
		{
			return Clamp((60.0 - Math.Abs(angle)) / 50.0, 0.0, 1.0);
		}

		public static double LaneEase(double fromEnd)
		{
			return Clamp(fromEnd / 300.0, 0.0, 1.0);
		}

		public static double LaneEase(double along, double length)
		{
			return LaneEase(Math.Min(along, length - along));
		}

		public static double StraightEnd(double dx, double dz, double heading, out bool square)
		{
			square = false;
			double num = Math.Sqrt(dx * dx + dz * dz);
			if (num < 5.0 || num > 50.5)
			{
				return 0.0;
			}
			double num2 = (Math.Atan2(dx, dz) * 180.0 / Math.PI - heading + 90.0) % 180.0;
			if (num2 < 0.0)
			{
				num2 += 180.0;
			}
			double num3 = Math.Abs(num2 - 90.0);
			if (num3 <= 2.0)
			{
				return num;
			}
			if (num3 >= 88.0)
			{
				square = true;
				return num;
			}
			return 0.0;
		}

		public static double SlideLength(double dx, double dz)
		{
			double num = Math.Sqrt(dx * dx + dz * dz);
			if (!(num < 5.0) && !(num > 50.5))
			{
				return num;
			}
			return 0.0;
		}

		public static double StraightSlow(double angle)
		{
			return Clamp((6.0 - Math.Abs(angle)) / 4.0, 0.0, 1.0);
		}

		public static double PortEase(double fromBerth)
		{
			return Clamp((fromBerth - 10.0) / 40.0, 0.0, 1.0);
		}

		public static double InPortSpeed(double speed, double gap)
		{
			return speed * Clamp((gap - 8.0) / 20.0, 0.0, 1.0);
		}

		public static void PortOffsets(double fromBerth, double left, double right, double halfBeam, out double min, out double max)
		{
			min = 0.0 - (left - halfBeam - 2.0);
			max = right - halfBeam - 2.0;
			if (min > max)
			{
				min = (max = (right - left) / 2.0);
			}
			double num = PortEase(fromBerth);
			min *= num;
			max *= num;
		}

		public static double PassOffset(double min, double max, double lo, double hi, double halfBeam, double at)
		{
			double val = lo - halfBeam - 2.0;
			double val2 = hi + halfBeam + 2.0;
			double num = double.NaN;
			if (min <= Math.Min(max, val))
			{
				num = Clamp(at, min, Math.Min(max, val));
			}
			if (Math.Max(min, val2) <= max)
			{
				double num2 = Clamp(at, Math.Max(min, val2), max);
				if (double.IsNaN(num) || Math.Abs(num2 - at) < Math.Abs(num - at))
				{
					num = num2;
				}
			}
			return num;
		}

		public sta