using System; using UnityEngine; namespace BigShipTycoon { public enum SunPoolStyle { Automatic, None, Compact, Family, Resort, Lagoon } public enum SunPoolShape { Rectangle, Oval } public enum SunPoolPosition { Midship, Aft, Forward } public enum SunAttraction { Automatic, None, MiniGolf, Theater, GoKarts, RollerCoaster, Pool, SkyGarden } [Serializable] public struct SunDeckPlacement { public SunAttraction Kind; public int Column, Row, Rotation; [SerializeField] internal bool Included; public SunDeckPlacement(SunAttraction kind, int column, int row, int rotation = 0) { Kind = kind; Column = column; Row = row; Rotation = rotation; Included = false; } } [Serializable] public struct SunDeckPlan { public SunPoolStyle Pool; public SunPoolShape Shape; public SunPoolPosition Position; public SunAttraction Attraction; public bool NoShade, ExtraLoungers; public bool CustomLayout; public SunDeckPlacement[] Placements; internal int Code { get { int code = (int)Pool | (int)Shape << 3 | (int)Position << 4 | (int)Attraction << 6 | (NoShade ? 1 << 9 : 0) | (ExtraLoungers ? 1 << 10 : 0) | (CustomLayout ? 1 << 11 : 0); if (CustomLayout && Placements != null) foreach (SunDeckPlacement item in Placements) code = unchecked(code * 109 + ((int)item.Kind | item.Rotation << 3 | item.Row << 5 | item.Column << 9)); return code; } } internal static int PoolPriceFor(SunPoolStyle pool) => pool switch { SunPoolStyle.Compact => 9500, SunPoolStyle.Family => 21000, SunPoolStyle.Resort => 59000, SunPoolStyle.Lagoon => 145000, _ => 0 }; internal static int AttractionPrice(SunAttraction kind) => kind switch { SunAttraction.MiniGolf => 16000, SunAttraction.Theater => 36000, SunAttraction.GoKarts => 62000, SunAttraction.RollerCoaster => 145000, SunAttraction.SkyGarden => 124000, _ => 0 }; private static int PoolAdmissions(SunPoolStyle pool) => pool switch { SunPoolStyle.Compact => 42, SunPoolStyle.Family => 86, SunPoolStyle.Resort => 172, SunPoolStyle.Lagoon => 330, _ => 0 }; private static int AttractionAdmissions(SunAttraction kind) => kind switch { SunAttraction.MiniGolf => 52, SunAttraction.GoKarts => 78, SunAttraction.RollerCoaster => 124, SunAttraction.SkyGarden => 195, _ => 0 }; internal int AddedAmenities => CustomLayout ? AddedCapacity(false) : PoolAdmissions(Pool) + AttractionAdmissions(Attraction); internal int AddedShows => CustomLayout ? AddedCapacity(true) : Attraction == SunAttraction.Theater ? 110 : 0; private int AddedCapacity(bool shows) { int count = 0; if (Placements != null) foreach (SunDeckPlacement item in Placements) { if (item.Included) continue; count += shows ? item.Kind == SunAttraction.Theater ? 110 : 0 : item.Kind == SunAttraction.Pool ? PoolAdmissions(Pool) : AttractionAdmissions(item.Kind); } return count; } internal bool ValidOptions(int hull) => (uint)Pool <= (uint)SunPoolStyle.Lagoon && (uint)Shape <= (uint)SunPoolShape.Oval && (uint)Position <= (uint)SunPoolPosition.Forward && (uint)Attraction <= (uint)SunAttraction.RollerCoaster && hull >= RequiredHull(Pool) && hull >= RequiredHull(Attraction); internal static int RequiredHull(SunPoolStyle pool) => pool switch { SunPoolStyle.Resort => Market.Regional, SunPoolStyle.Lagoon => Market.Mega, _ => 0 }; internal static int RequiredHull(SunAttraction attraction) => attraction switch { SunAttraction.Theater or SunAttraction.GoKarts => Market.Regional, SunAttraction.RollerCoaster => Market.Ocean, SunAttraction.SkyGarden => Market.Mega, _ => 0 }; } public sealed partial class Ship { [SerializeField] private SunDeckPlan sunDeckPlan; [SerializeField] private SunDeckPlan aftSunDeckPlan; public SunDeckPlan SunDeckPlan => SunDeckFor(SunDeckZone.Sky); public bool HasAftTerrace => HullIndex == Market.Mega; internal int OutdoorAmenityCapacity => sunDeckPlan.AddedAmenities + (HasAftTerrace ? aftSunDeckPlan.AddedAmenities : 0); internal int OutdoorShowCapacity => sunDeckPlan.AddedShows + (HasAftTerrace ? aftSunDeckPlan.AddedShows : 0); internal int SunDeckPlanCode => HasAftTerrace ? unchecked(sunDeckPlan.Code * 109 + aftSunDeckPlan.Code) : sunDeckPlan.Code; internal bool HasValidSunDeckPlan => sunDeckPlan.ValidOptions(HullIndex) && (!HasAftTerrace || SunDeckFor(SunDeckZone.AftTerrace).ValidOptions(HullIndex)) && SunDecksFitAt(Decks.Count); public SunDeckPlan SunDeckFor(SunDeckZone zone) { SunDeckPlan stored = zone == SunDeckZone.AftTerrace ? aftSunDeckPlan : sunDeckPlan; return stored.CustomLayout || !HasAftTerrace ? stored : new SunDeckPlan { CustomLayout = true, Pool = SunPoolStyle.Compact, Attraction = SunAttraction.None }; } internal bool SupportsSunDeck(SunDeckZone zone) => zone == SunDeckZone.Sky || zone == SunDeckZone.AftTerrace && HasAftTerrace; internal bool SunDecksFitAt(int count) => (!sunDeckPlan.CustomLayout || new SunDeckGrid(this, count).Valid(sunDeckPlan)) && (!HasAftTerrace || new SunDeckGrid(this, count, SunDeckZone.AftTerrace).Valid(SunDeckFor(SunDeckZone.AftTerrace))); internal void SetSunDeckPlan(SunDeckPlan plan, SunDeckZone zone) { if (zone == SunDeckZone.AftTerrace) aftSunDeckPlan = plan; else sunDeckPlan = plan; } } public sealed partial class Company { internal static int SunDeckCost(Ship ship, SunDeckPlan next, SunDeckZone zone = SunDeckZone.Sky) { SunDeckPlan current = ship.SunDeckFor(zone); if (current.CustomLayout || next.CustomLayout) { var grid = new SunDeckGrid(ship, zone: zone); if (grid.PoolIndex < 0 || next.Pool == grid.SelectedPool) return 0; int priorPrice = grid.Existing[grid.PoolIndex].Included ? 0 : SunDeckPlan.PoolPriceFor(grid.SelectedPool); return Math.Max(0, SunDeckPlan.PoolPriceFor(next.Pool) - priorPrice); } int pool = Math.Max(0, SunDeckPlan.PoolPriceFor(next.Pool) - SunDeckPlan.PoolPriceFor(current.Pool)); int attraction = next.Attraction == current.Attraction ? 0 : Math.Max(0, SunDeckPlan.AttractionPrice(next.Attraction) - SunDeckPlan.AttractionPrice(current.Attraction) / 4); return pool + attraction; } public string ChangeSunDeck(Ship ship, SunDeckPlan next, SunDeckZone zone = SunDeckZone.Sky) { if (ship == null || !Fleet.Contains(ship)) return "Choose a ship from your fleet."; if (!ship.SupportsSunDeck(zone)) return "The split aft terrace requires a MEGA Ocean Liner."; if (!next.ValidOptions(ship.HullIndex)) return "This fitting requires a larger hull."; int cost = SunDeckCost(ship, next, zone); var grid = new SunDeckGrid(ship, zone: zone); if (ship.SunDeckFor(zone).CustomLayout || next.CustomLayout) { int pool = grid.PoolIndex; if (next.Pool is SunPoolStyle.None or SunPoolStyle.Automatic) next.Pool = grid.SelectedPool; next = grid.Customize(next); if (pool >= 0 && next.Pool != grid.SelectedPool) next.Placements[pool].Included = false; if (!grid.Valid(next)) return "The new pool footprint needs more room. Move or turn the pool first."; } if (AvailableCash < cost) return $"The company needs ${cost:N0} available for this refit."; Cash -= cost; ship.SetSunDeckPlan(next, zone); return null; } internal static int SunDeckPlacementPrice(Ship ship, SunDeckPlacement placement, int replacing = -1, SunDeckZone zone = SunDeckZone.Sky) { if (replacing >= 0) return 0; return placement.Kind == SunAttraction.Pool ? SunDeckPlan.PoolPriceFor(new SunDeckGrid(ship, zone: zone).SelectedPool) : SunDeckPlan.AttractionPrice(placement.Kind); } public string SunDeckPlacementBlock(Ship ship, SunDeckPlacement placement, int replacing = -1, SunDeckZone zone = SunDeckZone.Sky) { if (ship == null || !Fleet.Contains(ship)) return "Choose a ship from your fleet."; if (!ship.SupportsSunDeck(zone)) return "The split aft terrace requires a MEGA Ocean Liner."; var grid = new SunDeckGrid(ship, zone: zone); string block = grid.PlacementBlock(placement, grid.SelectedPool, grid.Existing, replacing); if (block != null) return block; return AvailableCash < SunDeckPlacementPrice(ship, placement, replacing, zone) ? "The company needs more cash." : null; } public string PlaceSunDeck(Ship ship, SunDeckPlacement placement, int replacing = -1, SunDeckZone zone = SunDeckZone.Sky) { string block = SunDeckPlacementBlock(ship, placement, replacing, zone); if (block != null) return block; var grid = new SunDeckGrid(ship, zone: zone); SunDeckPlan next = grid.Customize(ship.SunDeckFor(zone), replacing < 0 ? 1 : 0); int index = replacing < 0 ? next.Placements.Length - 1 : replacing; placement.Included = replacing >= 0 && next.Placements[index].Included; next.Placements[index] = placement; Cash -= SunDeckPlacementPrice(ship, placement, replacing, zone); ship.SetSunDeckPlan(next, zone); return null; } public string RemoveSunDeck(Ship ship, int index, SunDeckZone zone = SunDeckZone.Sky) { if (ship == null || !Fleet.Contains(ship)) return "Choose a ship from your fleet."; if (!ship.SupportsSunDeck(zone)) return "The split aft terrace requires a MEGA Ocean Liner."; var grid = new SunDeckGrid(ship, zone: zone); if ((uint)index >= (uint)grid.Existing.Count) return "Select a fitted attraction to remove."; SunDeckPlan next = grid.Customize(ship.SunDeckFor(zone), omit: index); SunDeckPlacement removed = grid.Existing[index]; if (!removed.Included) Cash += SunDeckPlacementPrice(ship, removed, zone: zone) / 4; ship.SetSunDeckPlan(next, zone); return null; } } }